Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* -------------------------------------------------
- The purpose of this program is to simulate a
- basic ATM machine and display four key options:
- deposit, withdraw, check balance, and exit.
- A switch statement must be used.
- ------------------------------------------------ */
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- // Assume a balance of $500.00 for all users.
- #define BALANCE 500.00
- // Declare variables.
- int iMenuSelect = 0;
- double dUserDeposit = 0.0, dNewBalance = 0.0;
- double dUserWithdraw = 0.0;
- //Print the menu to the console.
- printf("\t*******************\n");
- printf("\t1 - Deposit\n");
- printf("\t2 - Withdraw\n");
- printf("\t3 - Check Balance\n");
- printf("\t4 - Exit\n");
- printf("\t*******************\n\n");
- //Prompt the user for their selection and store the value.
- printf("Please type the number of the option you would like to perform > ");
- scanf("%d", &iMenuSelect);
- //Begin switch statement of variable iMenuSelect.
- switch(iMenuSelect)
- {
- // Deposit, create new balance.
- case 1:
- // Ask for deposit amount, then add it and print new balance.
- printf("\nHow much would you like to deposit? > ");
- scanf("%lf", &dUserDeposit);
- // Create and display new balance after deposit.
- dNewBalance = dUserDeposit + BALANCE;
- printf("\nYour new balance is $%.2f.\n", dNewBalance);
- break;
- // Withdraw, create new balance.
- case 2:
- // Ask for withdraw amount, then subtract it and print new balance.
- printf("\nHow much would you like to withdraw? > ");
- scanf("%lf", &dUserWithdraw);
- // Create and display new balance.
- dNewBalance = BALANCE - dUserWithdraw;
- if(dUserWithdraw <= 500)
- {
- printf("\nHere is your money. Your new balance is $%.2f.\n", dNewBalance);
- }
- else
- {
- printf("\nYou have insufficient funds.\n");
- }
- break;
- // Check balance, display BALANCE.
- case 3:
- // Display balance.
- printf("\nYour balance is %.2f\n", BALANCE);
- break;
- // Exit program.
- case 4: exit(EXIT_FAILURE);
- break;
- default: printf("\n\nWARNING: Invalid option selected.\n\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement