Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. /* -------------------------------------------------
  2. The purpose of this program is to simulate a
  3. basic ATM machine and display four key options:
  4. deposit, withdraw, check balance, and exit.
  5. A switch statement must be used.
  6. ------------------------------------------------ */
  7.  
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11.  
  12. int main()
  13. {
  14.  
  15. // Assume a balance of $500.00 for all users.
  16. #define BALANCE 500.00
  17.  
  18. // Declare variables.
  19. int iMenuSelect = 0;
  20. double dUserDeposit = 0.0, dNewBalance = 0.0;
  21. double dUserWithdraw = 0.0;
  22.  
  23. //Print the menu to the console.
  24. printf("\t*******************\n");
  25. printf("\t1 - Deposit\n");
  26. printf("\t2 - Withdraw\n");
  27. printf("\t3 - Check Balance\n");
  28. printf("\t4 - Exit\n");
  29. printf("\t*******************\n\n");
  30.  
  31. //Prompt the user for their selection and store the value.
  32. printf("Please type the number of the option you would like to perform > ");
  33. scanf("%d", &iMenuSelect);
  34.  
  35. //Begin switch statement of variable iMenuSelect.
  36. switch(iMenuSelect)
  37. {
  38. // Deposit, create new balance.
  39. case 1:
  40.  
  41. // Ask for deposit amount, then add it and print new balance.
  42. printf("\nHow much would you like to deposit? > ");
  43. scanf("%lf", &dUserDeposit);
  44.  
  45. // Create and display new balance after deposit.
  46. dNewBalance = dUserDeposit + BALANCE;
  47.  
  48. printf("\nYour new balance is $%.2f.\n", dNewBalance);
  49. break;
  50.  
  51. // Withdraw, create new balance.
  52. case 2:
  53.  
  54. // Ask for withdraw amount, then subtract it and print new balance.
  55. printf("\nHow much would you like to withdraw? > ");
  56. scanf("%lf", &dUserWithdraw);
  57.  
  58. // Create and display new balance.
  59. dNewBalance = BALANCE - dUserWithdraw;
  60.  
  61. if(dUserWithdraw <= 500)
  62. {
  63. printf("\nHere is your money. Your new balance is $%.2f.\n", dNewBalance);
  64. }
  65.  
  66. else
  67. {
  68. printf("\nYou have insufficient funds.\n");
  69. }
  70.  
  71. break;
  72.  
  73. // Check balance, display BALANCE.
  74. case 3:
  75.  
  76. // Display balance.
  77. printf("\nYour balance is %.2f\n", BALANCE);
  78.  
  79. break;
  80.  
  81. // Exit program.
  82. case 4: exit(EXIT_FAILURE);
  83. break;
  84.  
  85. default: printf("\n\nWARNING: Invalid option selected.\n\n");
  86. }
  87.  
  88. return 0;
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement