-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
88 lines (78 loc) · 2.31 KB
/
Main.cpp
File metadata and controls
88 lines (78 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <vector>
#include <string>
#include <array>
struct InputCash
{
public:
float PaymentTotal;
InputCash(float Payment)
{
PaymentTotal = Payment;
}
};
struct VendingMachineItems
{
public:
int m_DrinkID;
std::string m_DrinkName;
double m_DrinkCost;
VendingMachineItems(int DrinkID, std::string DrinkName, double DrinkCost)
{
m_DrinkCost = DrinkCost;
m_DrinkID = DrinkID;
m_DrinkName = DrinkName;
}
};
int main()
{
// All items inside vending machine
std::vector<VendingMachineItems> VendingItems;
VendingItems.push_back(VendingMachineItems(0, "Gatorade", 6.50));
VendingItems.push_back(VendingMachineItems(1, "Coca Cola", 4.50));
VendingItems.push_back(VendingMachineItems(2, "Lemonade", 2.50));
VendingItems.push_back(VendingMachineItems(3, "Powerade", 6.25));
VendingItems.push_back(VendingMachineItems(4, "Rockstar", 5.00));
VendingItems.push_back(VendingMachineItems(5, "Red bull", 6.25));
VendingItems.push_back(VendingMachineItems(6, "Pepsi", 3.50));
VendingItems.push_back(VendingMachineItems(7, "Water", 4.00));
while (true)
{
for (const VendingMachineItems& item : VendingItems)
{
std::cout << " ItemID: " << item.m_DrinkID << " Name: " << item.m_DrinkName << " Cost: " << item.m_DrinkCost << std::endl;
}
size_t ChosenItem;
std::cout << "Enter your choice: " << std::endl;
std::cin >> ChosenItem;
size_t Payment;
if (ChosenItem >= 0 && ChosenItem < VendingItems.capacity())
{
// Purchasing System
std::cout << "Your choice: " << VendingItems[ChosenItem].m_DrinkID << " and the price is: " << VendingItems[ChosenItem].m_DrinkCost;
std::cout << " Please Insert Money: " << std::endl;
std::cin >> Payment;
std::cout << " You payed: " << Payment;
float total = Payment - VendingItems[ChosenItem].m_DrinkCost;
std::cout << " Here is your change " << total;
}
std::cout << " Thank you for your purchase!" << std::endl;
// System to purchase another item
std::string WantAnotherItem;
std::cout << " Do you want another item? (Y/N)" << std::endl;
std::cin >> WantAnotherItem;
if (WantAnotherItem == "n" || WantAnotherItem == "N")
{
std::cout << "Thank you for your purchase!" << std::endl;
break;
}
else if (WantAnotherItem == "y" || WantAnotherItem == "Y")
{
std::cout << std::endl;
}
else
{
return 0;
}
}
}