Hi! I need some guidance on this project. I wrote most of it, but i would like to improve my code by implementing more functions, and im open to hear suggestions on my code. My main concern is, every time the user picks one of the drinks it should subtract 1 from the total 20 available, and whenever the quantity available reaches 0 display a message. How can i do this?? Thanks in advance for those willing to help.
PS. I read the info from a file!
//Display Menu
do
{
earnings += payment - change;
selection = displayMenu(drinksList, selection);
while(selection > 7 || selection < 1)
{
cout << "Please enter one of the available options: ";
cin >> selection;
}
if(selection !=7)
{
switch(selection)
{
case 1:
system("cls");
cout << "You chose: Coca-Cola\n";
cout <<"Please enter the amount of money to be paid: ";
cin >> payment;
if((payment <= 0.00) || (payment >= 1.00))
{
cout <<"That's an invalid amount of change.\n";
cout <<"Please re-enter your amount: ";
cin >> payment;
change = payment - drinksList[0].cost;
cout <<"Your change is: $" << change << endl <<endl;
}
else
{
change = payment - drinksList[0].cost;
cout <<"Your change is: $" << change << endl <<endl;
}
drinksList[0].quantity - 1;
break;
case 2:
system("cls");
cout << "You chose: Root-Beer\n";
cout <<"Please enter the amount of money to be paid: ";
cin >> payment;
if((payment <= 0.00) || (payment >= 1.00))
{
cout <<"That's an invalid amount of change.\n";
cout <<"Please re-enter your amount: ";
cin >> payment;
change = payment - drinksList[0].cost;
cout <<"Your change is: $" << change << endl <<endl;
}
else
{
change = payment - drinksList[0].cost;
cout <<"Your change is: $" << change << endl <<endl;
}
break;
case 3:
system("cls");
cout << "You chose: Sprite\n";
cout <<"Please enter the amount of money to be paid: ";
cin >> payment;
if((payment <= 0.00) || (payment >= 1.00))
{
cout <<"That's an invalid amount of change.\n";
cout <<"Please re-enter your amount: ";
cin >> payment;
change = payment - drinksList[0].cost;
cout <<"Your change is: $" << change << endl <<endl;
}
else
{
change = payment - drinksList[0].cost;
cout <<"Your change is: $" << change << endl <<endl;
}
break;
case 4:
system("cls");
cout << "You chose: Spring-Water\n";
cout <<"Please enter the amount of money to be paid: ";
cin >> payment;
if((payment <= 0.00) || (payment >= 1.00))
{
cout <<"That's an invalid amount of change.\n";
cout <<"Please re-enter your amount: ";
cin >> payment;
change = payment - drinksList[0].cost;
cout <<"Your change is: $" << change << endl <<endl;
}
else
{
change = payment - drinksList[0].cost;
cout <<"Your change is: $" << change << endl <<endl;
}
break;
case 5:
system("cls");
cout << "You chose: Apple-Juice\n";
cout <<"Please enter the amount of money to be paid: ";
cin >> payment;
if((payment <= 0.00) || (payment >= 1.00))
{
cout <<"That's an invalid amount of change.\n";
cout <<"Please re-enter your amount: ";
cin >> payment;
change = payment - drinksList[0].cost;
cout <<"Your change is: $" << change << endl <<endl;
}
else
{
change = payment - drinksList[0].cost;
cout <<"Your change is: $" << change << endl <<endl;
}
break;
case 6:
system("cls");
cout <<"Thank you for using the program.\n";
cout <<"This machine has earned: $"
<< earnings << "." <<endl <<endl;
break;
case 7:
cout <<"Thank you for using the program.\n";
break;
}
}
}while(selection !=7);
system("PAUSE");
return EXIT_SUCCESS;
}