fork download
  1. //Ryan Shahriyarpour CS1A Carl Argila CH4 HW Q:4
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Change for a Dollar Game
  6.  *
  7.  *********************
  8.  *
  9.  * Create a change-counting game that gets the user to enter the number of
  10.  * coins required to make exactly one dollar. The program asks for the number
  11.  * of pennies, nickels, dimes, and quarters. If the total value equals one
  12.  * dollar, then it will the user. Otherwise, it will show whether the amount is more
  13.  * or less than one dollar.
  14.  *
  15.  * INPUT
  16.  * pennies : Number of pennies (1 cent each)
  17.  * nickels : Number of nickels (5 cents each)
  18.  * dimes : Number of dimes (10 cents each)
  19.  * quarters : Number of quarters (25 cents each)
  20.  *
  21.  * OUTPUT
  22.  * Message indicating if player won or the amount difference
  23.  *
  24.  ****************************************************************************/
  25.  
  26. #include <iostream>
  27. using namespace std;
  28.  
  29. int main()
  30. {
  31. const int ONE_DOLLAR = 100;
  32. const int PENNY = 1;
  33. const int NICKEL = 5;
  34. const int DIME = 10;
  35. const int QUARTER = 25;
  36.  
  37. int pennies;
  38. int nickels;
  39. int dimes;
  40. int quarters;
  41. int total;
  42.  
  43. cout << "Welcome to the Change for a Dollar Game!\n";
  44. cout << "Enter the number of pennies: ";
  45. cin >> pennies;
  46. cout << "Enter the number of nickels: ";
  47. cin >> nickels;
  48. cout << "Enter the number of dimes: ";
  49. cin >> dimes;
  50. cout << "Enter the number of quarters: ";
  51. cin >> quarters;
  52.  
  53. total = (pennies * PENNY) + (nickels * NICKEL) +
  54. (dimes * DIME) + (quarters * QUARTER);
  55.  
  56. if (total == ONE_DOLLAR)
  57. {
  58. cout << "Congratulations! You won!\n";
  59. }
  60. else if (total > ONE_DOLLAR)
  61. {
  62. cout << "You have " << (total - ONE_DOLLAR) << " cents too much.\n";
  63. }
  64. else
  65. {
  66. cout << "You have " << (ONE_DOLLAR - total) << " cents too little.\n";
  67. }
  68.  
  69. return 0;
  70. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Welcome to the Change for a Dollar Game!
Enter the number of pennies: Enter the number of nickels: Enter the number of dimes: Enter the number of quarters: You have 451366469 cents too little.