fork download
  1. // Nathanael Schwartz CS1A Chapter 4, P. 221, #8
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * COUNT CHANGE
  6.  * _____________________________________________________________________________
  7.  * This program asks the user to enter the number of pennies, nickels, dimes,
  8.  * and quarters, and calculates the total amount. If the total equals exactly
  9.  * one dollar, the user wins the game. Otherwise, the program informs the user
  10.  * if the amount is less than or greater than one dollar.
  11.  * _____________________________________________________________________________
  12.  * INPUT
  13.  * pennies : Number of pennies
  14.  * nickels : Number of nickels
  15.  * dimes : Number of dimes
  16.  * quarters : Number of quarters
  17.  *
  18.  * OUTPUT
  19.  * total : Total amount of coins
  20.  *
  21.  ******************************************************************************/
  22. #include <iostream>
  23. using namespace std;
  24.  
  25. int main() {
  26. // Declare variables
  27. int pennies; // INPUT - Number of pennies
  28. int nickels; // INPUT - Number of nickels
  29. int dimes; // INPUT - Number of dimes
  30. int quarters; // INPUT - Number of quarters
  31. double total; // OUTPUT - Total value of coins
  32.  
  33. // Input values from user
  34. cout << "Enter the number of pennies: \n";
  35. cin >> pennies;
  36. cout << "Enter the number of nickels: \n";
  37. cin >> nickels;
  38. cout << "Enter the number of dimes: \n";
  39. cin >> dimes;
  40. cout << "Enter the number of quarters: \n";
  41. cin >> quarters;
  42.  
  43. // Calculate total value of coins
  44. total = pennies * 0.01 + nickels * 0.05 + dimes * 0.10 + quarters * 0.25;
  45.  
  46. // Output results
  47. if (total == 1.00)
  48. cout << "Congratulations! The total is exactly one dollar. You win!\n";
  49. else if (total < 1.00)
  50. cout << "The total is less than one dollar.\n";
  51. else
  52. cout << "The total is more than one dollar.\n";
  53.  
  54.  
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0s 5272KB
stdin
10
5
4
1
stdout
Enter the number of pennies: 
Enter the number of nickels: 
Enter the number of dimes: 
Enter the number of quarters: 
Congratulations! The total is exactly one dollar. You win!