1 At the end of the program total the amount of money put in
Solution
//Vending Machine Program
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
double product1 = 0.60;
double product2 = 1.85;
double product3 = 1.70;
double product4 = 0.90;
double product5 = 0.75;
double product6 = 1.10;
double product7 = 1.45;
double product8 = 1.25;
double customerMoney = 0.00;
double expense = 0.00;
ofstream outfile;
outfile.open(\"GroupNameVendingMachine.txt\");
cout << \"How much money do you have? \";
cin >> customerMoney;
while (customerMoney >= 59.99)
{
int customerChoice = 0;
int exitProgram = 0;
cout << \"Which product would you like to buy?\ Enter \'1\' for Candy Bar: ($0.60)\ Enter \'2\' for Energy Bar ($1.85)\ Enter \'3\' for Energy Drink ($1.70)\ Enter \'4\' for Hard Candy ($0.90)\ Enter \'5\' for Popcorn ($0.75)\ Enter \'6\' for Potato Chips ($1.10)\ Enter \'7\' for Soda ($1.45)\ Enter \'8\' for Water ($1.25)\ Enter \'9\' for Exit\ \";
cin >> customerChoice;
if (customerChoice == 1)
{
cout << \"You have selected Candy Bar: \ \";
customerMoney = customerMoney - product1;
expense = expense - product1;
outfile << \"Candy Bar \" << product1 << endl ;
cout << \"You have $\" << customerMoney << \" left\ \";
}
else if (customerChoice == 2)
{
cout << \"You have selected Energy Bar \ \";
customerMoney = customerMoney - product2;
expense = expense - product2;
outfile << \"Energy Bar \" << product2 << endl ;
cout << \"You have $\" << customerMoney << \" left\ \";
}
else if (customerChoice == 3)
{
cout << \"You have selected Energy Drink\ \";
customerMoney = customerMoney - product3;
expense = expense - product3;
outfile << \"Energy Drink \" << product3 << endl ;
cout << \"You have $\" << customerMoney << \" left\ \";
}
else if (customerChoice == 4)
{
cout << \"You have selected Hard Candy\ \";
customerMoney = customerMoney - product4;
expense = expense - product4;
outfile << \"Hard Candy \" << product4 << endl ;
cout << \"You have $\" << customerMoney << \" left\ \";
}
else if (customerChoice == 5)
{
cout << \"You have selected Popcorn\ \";
customerMoney = customerMoney - product5;
expense = expense - product5;
outfile << \"Popcorn \" << product5 << endl;
cout << \"You have $\" << customerMoney << \" left\ \";
}
else if (customerChoice == 6)
{
cout << \"You have selected Potato Chips\ \";
customerMoney = customerMoney - product6;
expense = expense - product6;
outfile << \"Potato Chips \" << product6 << endl ;
cout << \"You have $\" << customerMoney << \" left\ \";
}
else if (customerChoice == 7)
{
cout << \"You have selected Soda\ \";
customerMoney = customerMoney - product7;
expense = expense - product7;
outfile << \"Soda \" << product7 << endl ;
cout << \"You have $\" << customerMoney << \" left\ \";
}
else if (customerChoice == 8)
{
cout << \"You have selected Water\ \";
customerMoney = customerMoney - product8;
expense = expense - product8;
outfile << \"Water \" << product8 << endl ;
cout << \"You have $\" << customerMoney << \" left\ \";
}
else if (customerChoice == 9)
{
outfile << \" total \" <<expense << endl;
break;
}
}
cin.ignore();
cin.get();
return 0;
}


