Advertisement
SmellyBadger

Untitled

Oct 9th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. int main()
  2. {
  3. cout << fixed << showpoint << setprecision(2);
  4. char action; // Deposit, Withdrawal, Interest, and Closeout
  5.  
  6. int initialBalance; // initial balance entered by the user must be between 1 and 1000
  7. int Amount; // this is my second operand
  8. int numBillsDispensed; // the number of bills dispensed
  9. float newBalance; // the balance after the action has taken place
  10. bool isInvalid = false;
  11.  
  12. cout << "Enter the initial balance [1-1000]: " << endl;
  13. cin >> initialBalance;
  14.  
  15. cout << "Enter an action (D, W, I or C): " << endl;
  16. cin >> action;
  17.  
  18. cout << "Enter the second operand: " << endl;
  19. cin >> Amount;
  20.  
  21. if (action == 'D')
  22. {
  23. if (Amount > 1000 || Amount < 1)
  24. {
  25. cout << "Input out of range" << endl;
  26. isInvalid = true;
  27. }
  28. if (isInvalid == false)
  29. {
  30. newBalance = initialBalance + Amount;
  31. cout << "The new account balance is " << newBalance << endl;
  32. }
  33. }
  34. if (action == 'W')
  35. {
  36. if (Amount < 1 || Amount > initialBalance)
  37. {
  38. cout << "Input out of range" << endl;
  39. isInvalid = true;
  40. }
  41. if (isInvalid == false)
  42. {
  43. newBalance = initialBalance - Amount;
  44. cout << "The new account balance is " << newBalance << endl;
  45. }
  46. }
  47. if (action == 'I')
  48. {
  49. if (Amount < 1 || Amount > 15)
  50. {
  51. cout << "Input out of range" << endl;
  52. isInvalid = true;
  53. }
  54. if (isInvalid == false)
  55. {
  56. newBalance = (float)initialBalance + (((float)Amount / 100.0)*(float)initialBalance);
  57. cout << "The new account balance is " << newBalance << endl;
  58. }
  59. }
  60. if (action == 'C')
  61. {
  62. if (Amount != 20 && Amount != 10 && Amount != 5)
  63. {
  64. cout << "Input out of range" << endl;
  65. isInvalid = true;
  66. }
  67. if (isInvalid == false)
  68. {
  69. numBillsDispensed = initialBalance / Amount;
  70. newBalance = initialBalance - (numBillsDispensed * Amount);
  71. cout << numBillsDispensed << " bills dispensed plus " << newBalance << endl;
  72. }
  73. }
  74. if (action != 'D' && action != 'W' && action != 'I' && action != 'C')
  75. {
  76. cout << "Input out of range" << endl;
  77. isInvalid = true;
  78. }
  79. cin.get();
  80. cin.get();
  81.  
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement