Write a C++ program for simple ATM Simulation to Check Balance, Deposit, and Withdraw money.
#include <iostream>
using namespace std;
int main() {
int option;
double balance = 1000.0; // Initial balance
double depositAmount;
double withdrawAmount;
while (true) {
// Display the menu
cout << "ATM Menu:\n";
cout << "1. Check Balance\n";
cout << "2. Deposit\n";
cout << "3. Withdraw\n";
cout << "4. Exit\n";
cout << "Enter your option (1-4): ";
cin >> option;
// Handle the user's choice
switch (option) {
case 1:
// Check balance
cout << "Your current balance is: $" << balance << endl;
break;
case 2:
// Deposit
cout << "Enter deposit amount: $";
cin >> depositAmount;
balance += depositAmount;
cout << "Deposited $" << depositAmount << ". New balance is: $" << balance << endl;
break;
case 3:
// Withdraw
cout << "Enter withdraw amount: $";
cin >> withdrawAmount;
if (withdrawAmount > balance) {
cout << "Insufficient funds. Withdrawal denied." << endl;
} else {
balance -= withdrawAmount;
cout << "Withdrew $" << withdrawAmount << ". New balance is: $" << balance << endl;
}
break;
case 4:
// Exit
cout << "Exiting the ATM. Thank you!" << endl;
return 0; // Exit the program
default:
// Invalid option
cout << "Invalid option. Please enter a number between 1 and 4." << endl;
break;
}
}
return 0;
}
Possible Outputs
Output#1
ATM Menu:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your option (1-4): 1
Your current balance is: $1000.00
Output#2
ATM Menu:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your option (1-4): 2
Enter deposit amount: $500
Deposited $500.00. New balance is: $1500.00
Output#3
ATM Menu:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your option (1-4): 3
Enter withdraw amount: $200
Withdrew $200.00. New balance is: $1300.00\
Output#4
ATM Menu:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your option (1-4): 4
Exiting the ATM. Thank you!