-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
110 lines (93 loc) · 2.72 KB
/
main.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//******************************************************************
//Program Name: Vending Machine
//Author: Veronica Pichay
//IDE Used: Repl.it
//Created: Friday, July 17, 2020
//Program description: Inventory Management
//******************************************************************
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int SIZE = 5;
//Comment # 1 Struct var name
struct Beverage
{
//Comment # 2 Members
string name;
float cost;
int count;
};
//Comment # 3 Fx prototype
void dclre (Beverage&, string , float, int);
int menu(Beverage[]);
void pay(float);
int main()
{
//Comment # 4 Initialization
int choice;
double rev = 0;
Beverage bev[5];
dclre (bev[0],"Cola", 0.75, 20);
dclre (bev[1],"Root Beer", 0.75, 20);
dclre (bev[2],"Lemon-Lime", 0.75, 20);
dclre (bev[3],"Grade Soda", 0.80, 20);
dclre (bev[4],"Cream Soda", 0.80, 20);
choice = menu (bev);
while(choice != 5) //Comment # 5 Condition of summation and subtraction if user don't exit
{
pay(bev[choice].cost);
rev += bev[choice].cost; //Comment # 6 updates earnings amount
bev[choice].count--; //Comment # 7 Updates inventory amount
choice = menu(bev);
}
cout<<"Total earning/s $"<< rev <<endl;
return 0;
}
void pay(float p) //Comment # 8 Fx that calculates the user transaction
{
float pay;
cout<<"\t> Price of the beverage is $" <<fixed <<p <<endl;
cout<<"\t> Enter amount of payment --> ";
cin>>pay;
//IVL
while (pay < 0.75 or pay > 1.00)
{
cout<<"\t> ERROR: Pay must be $0.75 to $1.00 only! --> ";
cin>>pay;
}
cout <<"\t> Don't forget to grab your $" <<fixed << pay - p<<" change!\n";cout <<"\t> Enjoy your beverage!\n";
}
//Comment # 9 Declares shortcut of each members
void dclre (Beverage& d,string n, float c, int count)
{
d.name = n;
d.cost = c;
d.count = count;
}
//Comment # 10 Purchase menu for user interactivity
int menu(Beverage b[])
{
int choice;
bool gone = true;
while ((choice < 1 or choice > 6) or gone)
{
gone = false;
cout << fixed << setprecision(2);
cout << "\nSoda machine inventory: \n";
cout << setw(15) << "\n \t> BEVERAGE \t" << setw(14) << "COST \t" << setw(10) << "On Hand \n";
cout << setw(8) << " \t> --------" << setw(11) << "\t----" << setw(10) << "\t -------\n";
for (int i = 0; i < SIZE; i++)
cout << "\t> " <<i + 1 << ". " << left << setw(15) << b[i].name << setw(11) << b[i].cost << left << b[i].count << endl;
cout<<" \t> 6. Quit\n";
cout<<"\nEnter Choice ";
cin >> choice;
if(choice < 1 or choice > 6) cout<<"Please choose from 1 to 6 only!";
else if (b[choice-1].count == 0)
{
cout<<"Please select a drink that is instock! \n";
gone = true;
}
}
return choice-1;
}