Sample Run 1
Welcome to CS126 Mart!
Item Codes Description Price
100 Sweet ‘n Ripe Grapes 125.35
101 Crunchy Apples 52.20
109 Green Peas 25.75
Enter Code: 128
Invalid code, please enter a valid one.
Enter Code: 100
Sweet ‘n Ripe Grapes 125.35
Quantity -3
Invalid Quantity, please enter again.
Quantity 2
Subtotal: 250.70
Enter Code: 101
Crunchy Apples 52.20
Quantity 1
Subtotal: 52.20
Enter Code: 0
Total Amount Due: 302.90
Cash: 100.00
Insufficient Cash!
Cash: 1000.00
Change: 697.10
=========== CHANGE BREAKDOWN ===========
1000 0 0
500 1 500.00
200 0 0
100 1 100.00
50 1 50.00
20 2 40.00
10 0 0
5 1 5.00
1 2 2.00
0.25 0 0
0.10 1 0.10
0.05 0 0
Do you want another transaction? <y/n> No.
#include <iostream>
using namespace std;
int main() {
int a = 1;
int code = 1;
float total = 0;
while (true) {
cout << "Sample run " << a << endl <<
"Welcome to CS126 Mart!" << endl <<
"Item Codes Description Price" << endl <<
"100 Sweet ‘n Ripe Grapes 125.35" << endl <<
"101 Crunchy Apples 52.20" << endl <<
"109 Green Peas 25.75";
"Enter Code: ";
while (code != 0) {
cout << endl << "Enter Code: ";
cin >> code;
switch (code) {
case 100:
cout << endl << "Sweet ‘n Ripe Grapes 125.35" << endl;
cout << "Quantity ";
int quant;
cin >> quant;
while (quant <= 0) {
cout << "Invalid Quantity, please enter again." << endl << "Quantity";
cin >> quant;
}
total += quant * 125.35;
cout << "Subtotal: " << quant * 125.35 << endl;
break;
case 101:
cout << endl << "Crunchy Apples 52.20" << endl;
cout << "Quantity ";
cin >> quant;
while (quant <= 0) {
cout << "Invalid Quantity, please enter again." << endl << "Quantity";
cin >> quant;
}
total += quant * 52.20;
cout << "Subtotal: " << quant * 52.20 << endl;
break;
case 109:
cout << endl << "Green Peas 25.75" << endl;
cout << "Quantity ";
cin >> quant;
while (quant <= 0) {
cout << "Invalid Quantity, please enter again." << endl << "Quantity";
cin >> quant;
}
total += quant * 25.75;
cout << "Subtotal: " << quant * 25.75 << endl;
break;
case 0:
break;
default:
cout << "Invalid code, please enter a valid one." << endl;
break;
}
}
cout <<
"Total amount due: " << total << endl;
float cash;
while (true) {
cout << "Cash: " << endl;
cin >> cash;
if(cash < total) {
cout << "Insufficient Cash!" << endl;
continue;
}
else {
cout << "Change: " << cash - total << endl;
break;
}
}
cout << "Do you want another transaction? <y/n>" << endl;
char a;
cin >> a;
if (a == 'n') {
break;
}
}
}
Comments
Leave a comment