Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a program that simulates a healthy drink machine. The program should
- //use functions to service arrays that store the following data.
- #include <iostream>
- #include <string>
- using namespace std;
- void buyDrink(int); //Max 5 per selection
- int main()
- {
- const int choices = 3; //Number of drink types
- string drinks[choices] = {"Green Tea - ", "\nKale Juice - ", "\nVery Berry Shake - "}; //Drink choices
- double drinkPrice[choices] = {1.25, 1.50 , 1.75}; //Drink prices
- int drinkAmount[choices] = {5,5,5}; //Amount of each in the machine
- int drinkType = 0;
- int drinksinMachine = 15;
- double change = 0;
- double moneyInserted = 0; //Money user enters
- double machineMade = 0; //Total machine made, initialized at 0 to accumulate.
- cout << "The drinks you may purchase are: \n\n";
- for(int count=0; count<choices; count++) //Drink display
- {
- cout << drinks[count];
- cout << drinkPrice[count];
- }
- //User decides whether to proceed with the program or to terminate it.
- toupper; //Changes lowercase to uppercase
- char response ='y';
- cout << " \n\nWould you like to purchase a drink from this machine? \n";
- cout << "If yes type 'Y', if not type 'N' and the program will exit. \n";
- cin >> response;
- while(toupper(response)!= 'N' && toupper(response)!= 'Y')
- {
- cout << "Please input 'N' or 'Y' "<< endl;
- cin >> response;
- }
- if(toupper(response) == 'N')
- return 0;
- else if (toupper(response) == 'Y')
- {
- int drinkKind;
- cout << "Enter 0 for Green Tea, 1 for Kale Juice, or 2 for Very Berry Shake. \n";
- cin >> drinkKind;
- while(drinkKind != 0 && drinkKind != 1 && drinkKind != 2)
- {
- cout << "Please choose only one drink. \n";
- cin >> drinkKind;
- }
- if(drinkKind == 0)
- cout << "You have chosen Green Tea. \n";
- if(drinkKind == 1)
- cout << "You have chosen Kale Juice. \n";
- if(drinkKind == 2)
- cout << "You have chosen Very Berry Shake. \n";
- cout << "Enter the amount of money to two decimal places that you will be inserting: \n";
- cin >> moneyInserted;
- if(moneyInserted>1.25 && moneyInserted <= 2.00)
- {
- cout << "You have inserted: $" << moneyInserted << endl;
- }
- else if(moneyInserted<1.25 || moneyInserted >2.00)
- {
- cout << "This machine will not accept anything less than $1.25 or greater \nthan $2.00. Try again: \n";
- cin >> moneyInserted;
- }
- change = moneyInserted - drinkPrice[drinkKind];
- if(change>0)
- {
- cout << "Your change is: $" << change << endl;
- machineMade+= moneyInserted-change;
- drinksinMachine--;
- cout << "This machine has accumulated: " << machineMade << endl;
- }
- else if(change<0)
- {
- cout << "You do not have enough money." << endl;
- cout << "Enter new amount." << endl;
- cin >> moneyInserted;
- }
- else
- {
- cout << "You have no change. Enjoy your drink! \n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement