-
Notifications
You must be signed in to change notification settings - Fork 0
/
cold_drinks-selling-software
74 lines (60 loc) · 1.86 KB
/
cold_drinks-selling-software
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
#include <iostream>
using namespace std;
struct Drink {
string name;
double cost;
int quantity;
};
const int NUM_DRINKS = 5;
void displayDrinks(const Drink drinks[]) {
cout << "Available drinks:\n";
for (int i = 0; i < NUM_DRINKS; i++) {
cout << i + 1 << ". " << drinks[i].name << " ($" << drinks[i].cost << ") - " << drinks[i].quantity << " no of drinks\n";
}
cout << "0. Quit\n";
}
int main() {
Drink drinks[NUM_DRINKS] = {
{"Cola", 0.75, 20},
{"Root Beer", 0.75, 20},
{"Lemon-Lime", 0.75, 20},
{"Grape Soda", 0.80, 20},
{"Cream Soda", 0.80, 20}
};
double totalMoneyEarned = 0.0;
while (1) {
displayDrinks(drinks);
int choice;
cout << "\nEnter your choice (0 to quit): ";
cin >> choice;
if (choice == 0) {
break;
} else if (choice < 0 || choice > NUM_DRINKS) {
cout << "Invalid choice. Try again.\n";
continue;
}
int index = choice - 1;
Drink selectedDrink = drinks[index];
if (selectedDrink.quantity == 0) {
cout << "Sorry, " << selectedDrink.name << " is sold out.\n";
continue;
}
double amount;
cout << "Insert money ($1.00 maximum): ";
cin >> amount;
if (amount < 0.0 || amount > 1.0) {
cout << "Invalid amount. Try again.\n";
continue;
}
if (amount < selectedDrink.cost) {
cout << "Insufficient amount. Please insert at least $" << selectedDrink.cost << ".\n";
continue;
}
double change = amount - selectedDrink.cost;
cout << "Change: $" << change << endl;
totalMoneyEarned += selectedDrink.cost;
drinks[index].quantity--;
}
cout << "Total money earned: $" << totalMoneyEarned << endl;
return 0;
}