May 2, 2011 at 1:46am UTC
I need help with my program, it is a soda machine and I need help adding Enumeration and Array. For enum I was going to list soda types, how can I add both enum and array ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
#include <iostream> //Basic input and output library//
#include <iomanip> //Currency output library//
using namespace std;
double machineTotal = 0.0; //Declare Variables//
int sodasPurchased = 0;
const double price = 1.00;
// Return total amount of money inserted.
double insertMoney()
{
// These can be local variables, and we'll return
// the total to the caller for when we need to give change.
double totalDeposited = 0.0;
double deposit = 0.0;
cout <<"Please enter $1.00" <<endl;
cin >> deposit;
totalDeposited += deposit;
// Loop until we've received enough money
while (totalDeposited < price)
{
cout << "Amount Needed: $" << price - totalDeposited << endl;
cin >> deposit;
totalDeposited += deposit;
}
machineTotal += totalDeposited;
return totalDeposited;
}
void giveChange(const double amountDeposited)
{
double changeDue = amountDeposited - price;
if (changeDue > 0.0)
{
cout << "You have inserted $" << amountDeposited << endl;
cout << "Please take your change of $" << changeDue << endl;
machineTotal -= changeDue;
}
}
void displayMenu()
{
int selection = 0;
cout << "Thank you, please make your selection!" <<endl;
cout << "Coke - " << 0 << endl;
cout << "Sprite - " << 1 << endl;
cout << "Dr. Pepper - " << 2 << endl;
cin >> selection;
cout << endl;
while ( selection < 0 && selection > 3 )
{
cout << "Please select a choice between 0 and 2" << endl;
cout << "Thank you, please make your selection!" <<endl;
cout << "Coke - " << 0 << endl;
cout << "Sprite - " << 1 << endl;
cout << "Dr. Pepper - " << 2 << endl;
cin >> selection;
cout << endl;
}
switch (selection)
{
case 0:
cout << "Thank you and enjoy your Coke!" <<endl;
break ;
case 1:
cout << "Thank you and enjoy your Sprite!" <<endl;
break ;
case 2:
cout << "Thank you and enjoy your Dr.Pepper!" <<endl;
break ;
}
}
int main(void )
{
cout << "Welcome to the Coke Machine" << endl;
int question = 0;
do
{
double amountDeposited = insertMoney();
displayMenu();
giveChange(amountDeposited);
++sodasPurchased;
cout << "Would you like to purchase another soda? (1=yes 2=no)" << endl;
cin >> question;
} while (question == 1);
cout << "You dispensed " << sodasPurchased << " sodas." << endl;
cout << "The machine contains $" << machineTotal << endl;
return 0;
}
Last edited on May 2, 2011 at 1:49am UTC