Advertisement
jenniferleigh52

Change for a dollar game/Burgess

Aug 17th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. // Change for a Dollar Game
  2. // Jennifer Burgess
  3. // CSCI 193
  4. // Program 17
  5. // 6/28/14
  6. /* This program will play a dollar game with the user to enter the correct
  7. amount of coins that will add to a dollar and win the game.*/
  8.  
  9. #include "stdafx.h"
  10. #include <iostream>
  11.  
  12. using namespace std;
  13.  
  14.  
  15. int main()
  16. {
  17.     // Declare Variables
  18.     double quarters;
  19.     double quartersTotal;
  20.     double pennies;
  21.     double penniesTotal;
  22.     double dimes;
  23.     double dimesTotal;
  24.     double nickles;
  25.     double nicklesTotal;
  26.     double dollar;
  27.     double total;
  28.  
  29.     // Initialize Variables
  30.     quarters = 0; // Prompt user to input how many quarters
  31.     pennies = 0; // Prompt user to input how many pennies
  32.     dimes = 0; // Prompt user to input how many dimes
  33.     nickles =  0; // Prompt user to input how many nickles
  34.    
  35.     total = 100; // The amount that all coins must add up to
  36.  
  37.     // Prompt User
  38.     cout << "To win, enter how many quarters, dimes, nickles and pennies  \n";
  39.     cout << "are needed to make a dollar. " << endl;
  40.     cout << "Enter how many quarters:" << endl;
  41.     cin >> quarters;
  42.     quartersTotal = quarters * 25;
  43.     cout << "Enter how many dimes. " << endl;
  44.     cin >> dimes;
  45.     dimesTotal = dimes * 10;
  46.     cout << "Enter how many nickles. " << endl;
  47.     cin >> nickles;
  48.     nicklesTotal = nickles * 5;
  49.     cout << "Enter how many pennies. " << endl;
  50.     cin >> pennies;
  51.     penniesTotal = pennies * 1;
  52.    
  53.     dollar = quartersTotal + dimesTotal + nicklesTotal + penniesTotal;
  54.  
  55.     // Calculate data
  56.     if (dollar == total)
  57.         cout << "You won!" << endl;
  58.     else if (dollar > total)
  59.         cout << "Sorry, more than a dollar." << endl;
  60.     else
  61.         cout << "Sorry, less than a dollar." << endl;
  62.  
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement