earnings += payment;
cout << "Welcome to CMPSC 125's Drink Dispenser." << endl;
cout << "Created by Cedric Shumate" << endl;
cout <<"Please make a selection from the menu below:" << endl;
selection = displayMenu(selection);
if (selection == 1)
{
cout << "Please enter the amount of money to be paid: ";
cin >> payment;
do
{
cout << "That is an invalid amount of change. Please re-enter your amount.";
cin >> payment;
}
while ((payment <= 0) || (payment > 1));
change = drinkList[0].cost - payment;
cout << "Your change is $" << change << endl;
}
else if (selection == 2)
{
cout << "Please enter the amount of money to be paid: ";
cin >> payment;
do
{
cout << "That is an invalid amount of change. Please re-enter your amount.";
cin >> payment;
}
while ((payment <= 0) || (payment > 1));
change = drinkList[1].cost - payment;
cout << "Your change is $" << change << endl;
}
else if (selection == 3)
{
cout << "Please enter the amount of money to be paid: ";
cin >> payment;
do
{
cout << "That is an invalid amount of change. Please re-enter your amount.";
cin >> payment;
}
while ((payment <= 0) || (payment > 1));
change = drinkList[2].cost - payment;
cout << "Your change is $" << change << endl;
}
else if (selection == 4)
{
cout << "Please enter the amount of money to be paid: ";
cin >> payment;
do
{
cout << "That is an invalid amount of change. Please re-enter your amount.";
cin >> payment;
}
while ((payment <= 0) || (payment > 1));
change = drinkList[3].cost - payment;
cout << "Your change is $" << change << endl;
}
else if (selection == 5)
{
cout << "Please enter the amount of money to be paid: ";
cin >> payment;
do
{
cout << "That is an invalid amount of change. Please re-enter your amount.";
cin >> payment;
}
while ((payment <= 0) || (payment > 1));
change = drinkList[4].cost - payment;
cout << "Your change is $" << change << endl;
}
else if (selection == 6)
cout << "Thank you for using the program. This machine has earned $" << earnings << "." << endl;
else
{
cout << "Your selection is invalid. Please review the \nmenu and make another selection." << endl;
displayMenu(selection);
}
here is the feedback my teacher gave me but it seems vague:
1) should not have any global variables; was to pass by reference or value as needed
2) instead of having the numerous assignment statements to load the array, you should have used the braces as discussed in class and done it in 1 statement when declaring the array struct
3) Should only display the report heading and by line once
4) when I entered an invalid amount twice in a row, it took it and gave me negative change back -- error
5) when I entered 1.00 later, it said it was invalid, but 0 to 1.00 was to be valid -- error
6) you don't display the line with the soda and # remaining
7) when I continued to purchase same type of soda, I started getting error on amount even if I entered the exact amount
8) Never received sold out message
9) Needed to use while loops to validate inputs, not if else
10) you were to have GetChoice and ProcessTransaction functions; you just have one to Display the menu. Even it is wrong as it does not pull values from array, but just includes values in quotes for output
11) you had choice as a parameter, but then return its value, too; choice should have been a reference variable and the function void