fork download
  1. //Amari Mosley CSC5 Chapter 4, P.220 #5
  2. //
  3. /**************************************************************
  4. *
  5. * Computing Change for Dollar
  6. * ____________________________________________________________
  7. * This program will determine if an amount of change is equal
  8. * to, greater than, or less than a dollar.
  9. *
  10. * Computation is based on the conditional operator:
  11. * total = (pennies * 0.01) + (nickels * 0.05) + (dimes * 0.10)
  12. * + (quarters * 0.25)
  13. * ____________________________________________________________
  14. * INPUT
  15. * pennies : Number of pennies entered by user
  16. * nickels : Number of nickels entered by user
  17. * dimes : Number of dimes entered by user
  18. * quarters : Number of quarters entered by user
  19. *
  20. * OUTPUT
  21. * total : Calculated total dollar amount
  22. *
  23. * Displays whether the user won, or if the total was more/less
  24. * than $1.00
  25. *
  26. **************************************************************/
  27.  
  28. #include <iostream>
  29. #include <iomanip>
  30. using namespace std;
  31.  
  32. // Defining Main Function
  33. int main()
  34. {
  35. // Defining int Variables for counts and double for total
  36. int pennies; // Number of pennies entered by user
  37. int nickels; // Number of nickels entered by user
  38. int dimes; // Number of dimes entered by user
  39. int quarters; // Number of quarters entered by user
  40. double total; // Total value of the coins entered
  41.  
  42. // Prompting user to enter the number of coins
  43. cout << "Enter the number of pennies: ";
  44. cin >> pennies;
  45. cout << "Enter the number of nickels: ";
  46. cin >> nickels;
  47. cout << "Enter the number of dimes: ";
  48. cin >> dimes;
  49. cout << "Enter the number of quarters: ";
  50. cin >> quarters;
  51.  
  52. // Calculating total value of coins
  53. total = (pennies * 0.01) + (nickels * 0.05) + (dimes * 0.10) + (quarters * 0.25);
  54.  
  55. // Determining game result and displaying message
  56. if (total == 1.00)
  57. {
  58. cout << "Congratulations! You won the game by entering exactly one dollar!" << endl;
  59. }
  60. else if (total > 1.00)
  61. {
  62. cout << "The amount entered was more than one dollar." << endl;
  63. }
  64. else
  65. {
  66. cout << "The amount entered was less than one dollar." << endl;
  67. }
  68.  
  69. return 0;
  70. }
Success #stdin #stdout 0s 5308KB
stdin
1
2
3
4
stdout
Enter the number of pennies: Enter the number of nickels: Enter the number of dimes: Enter the number of quarters: The amount entered was more than one dollar.