1 At the end of the program total the amount of money put in

1. At the end of the program, total the amount of money put into the machine, and how many dollar bills, quarters, nickels, and dimes there are in the machine.
2. At the end of the program, write a text file of the items sold, and the total (i.e. all of 3 and 4 into a text file.) The text file should be named GroupNameVendingMachine.txt (where GroupName is your group’s name)
1. At the end of the program, total the amount of money put into the machine, and how many dollar bills, quarters, nickels, and dimes there are in the machine.
2. At the end of the program, write a text file of the items sold, and the total (i.e. all of 3 and 4 into a text file.) The text file should be named GroupNameVendingMachine.txt (where GroupName is your group’s name)
-----------------------------------------------------
There should be NO global variables.
There should choose from here:
? functions
? constant literals (numbers as well as strings)
? formatted output of information
? switch statements
? loops
? arrays
? conditionals
? file output
There should be NO global variables.
There should choose from here:
? functions
? constant literals (numbers as well as strings)
? formatted output of information
? switch statements
? loops
? arrays
? conditionals
? file output

You are going to build a simulator for a vending machine. The machine holds 8 different items: Taty Item Cost 5 Candy Bar $0.60 Energy Bar $1.85 5 Energy Drink $1.70 $0.90 5 Hard Candy 5 Popcorn $0.75 Potato Chips $1.10 5 soda $1.45 5 Water $1.25 The machine starts with 10 quarters, 20 dimes, and 30 nickels.

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;
}

 1. At the end of the program, total the amount of money put into the machine, and how many dollar bills, quarters, nickels, and dimes there are in the machine.
 1. At the end of the program, total the amount of money put into the machine, and how many dollar bills, quarters, nickels, and dimes there are in the machine.
 1. At the end of the program, total the amount of money put into the machine, and how many dollar bills, quarters, nickels, and dimes there are in the machine.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site