fork download
  1. //Jacklyn Isordia CSC5 Chapter 4, P. 221, #08
  2. //
  3. /**************************************************************
  4.  *
  5.  * Calculate the number of coins to get exactly one dollar
  6.  * ____________________________________________________________
  7.  *
  8.  * This program asks the user to enter a number of coins to make
  9.  * exactly one dollar. This includes pennies, nickels, dimes,
  10.  * and quarters when entered the correct amount of a single
  11.  * dollar the program will output a 'congratulations you've
  12.  * won! output.
  13.  * ____________________________________________________________
  14.  * INPUT
  15.  * pennies : number of pennies entered
  16.  * nickels : number of nickels entered
  17.  * dimes : number of dimes entered
  18.  * quarters : number of quarters entered
  19.  *
  20.  * OUTPUT
  21.  * total : displays win message if exactly $1.00 displays
  22.  * try again if over or under $1.00
  23.  *
  24.  * Formula
  25.  * total = (pennies *1) + (nickels * 5) + (dimes * 10) + (quarters * 25)
  26.  *
  27.  **************************************************************/
  28.  
  29. #include <iostream>
  30. using namespace std;
  31.  
  32. int main() {
  33. int pennies;
  34. int nickels;
  35. int dimes;
  36. int quarters;
  37. int total;
  38.  
  39. cout << "Enter the number of pennies\n";
  40. cin >> pennies;
  41. cout << "Enter the number of nickels\n";
  42. cin >> nickels;
  43. cout << "Enter the number of dimes\n";
  44. cin >> dimes;
  45. cout << "Enter the number of quarters\n";
  46. cin >> quarters;
  47.  
  48. total = (pennies * 1) + (nickels * 5) + (dimes * 10) + (quarters * 25);
  49.  
  50. if (total == 100) {
  51. cout << "Congratulations you've won!\n";
  52. }
  53. else if (total > 100) {
  54. cout << "Try again, you've went over the dollar amount.\n";
  55. }
  56. else {
  57. cout << "Try again, you've went under the dollar amount.\n";
  58. }
  59. return 0;
  60. }
Success #stdin #stdout 0.01s 5316KB
stdin
0
0
0
4
stdout
Enter the number of pennies
Enter the number of nickels
Enter the number of dimes
Enter the number of quarters
Congratulations you've won!