Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double total_check(double total);
- int main()
- {
- //variables
- int choice = 0;
- int dollars = 0;
- int quarters = 0;
- int dimes = 0;
- int nickels = 0;
- double const dollar = 1.00;
- double const quarter = 0.25;
- double const dime = 0.10;
- double const nickel = 0.05;
- double const twinkie = 3.50;
- double total = 0.00;
- double change = 0.00;
- cout.setf(ios::fixed);
- cout.setf(ios::showpoint);
- cout.precision(2);
- //Welcome message. Asks user for input. (dollars, quarters, dimes, nickels.)
- cout << "Hello, This is the Deep Fried Twinkie Machine. Deposit $3.50 for a Twinkie." << endl << "I accept dollars, quarters, qimesand nickels." << endl;
- do {
- // Menu
- cout << "1) Dollars " << endl;
- cout << "2) Quarters " << endl;
- cout << "3) Dimes " << endl;
- cout << "4) Nickels " << endl;
- cin >> choice;
- //Add and display coins and amount of money given by the user
- if (choice == 1) //Option for dollars
- {
- ++dollars;
- total = (total + dollar);
- }
- else if (choice == 2) //Option for Quarters
- {
- ++quarters;
- total = (total + quarter);
- }
- else if (choice == 3) //Option for Dimes
- {
- ++dimes;
- total = (total + dime);
- }
- else if (choice == 4) //Option for Nickels
- {
- ++nickels;
- total = (total + nickel);
- }
- else { //Displays error message for wrong input that isn't d/q/di/n
- cout << "Error" << endl;
- }
- //Display the change in coin amount and money
- cout << "You have entered the following coins: " << endl << "Dollars: " << dollars << endl;
- cout << "Quarters: " << quarters << endl << "Dimes: " << dimes << endl << "Nickels: " << nickels << endl;
- cout << "Total: $" << total << endl << endl;
- //Check change
- change = total_check(total);
- } while (total <= twinkie); //Program terminates if option = 0
- return 0;
- }
- double total_check(double total)
- {
- double change = 0.00;
- double const twinkie = 3.50;
- int choice;
- if (total >= twinkie) //Checks for input of $3.50
- {
- change = (total - twinkie);
- //Gives change if > 3.50
- cout << "\nYour change is: $" << change << endl << "Come back again soon!" << endl;
- }
- return(change);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement