In: Computer Science
Code C++ language description about Automated teller machine that can check balance, Deposit and Withdraw money
#include
#include
#include
using namespace std;
void showLogin() {
start:
system("cls"); //system clear
system("Color 0A"); //system color
string username, password;
char pw;
cout << "*****************ANT ATM MACHINE*****************" << endl;
cout << "Username: ";
cin >> username;
cout << "Password: ";
while (pw = getch()) {
if (pw == 13) {
if ((username == "user") && (password == "user1234")) {
break;
}
else {
cout << "Invalid Input...";
goto start;
}
} //13 is carriage return or enter from the keyboard
else if (pw == 8) {
if (sizeof(password) > 0) {
cout << "\b \b"; //b is backspace on screen
password.erase(password.length()-1);
}
} //8 is backspace or backspace from the keyboard
else {
cout << "*";
password = password + pw; //password string & pw is a char
}
}
system("cls");
}
void showMenu() {
cout << "*****************ANT ATM MACHINE*****************" << endl;
cout << "1. Check Balance" << endl;
cout << "2. Deposit" << endl;
cout << "3. Withdraw" << endl;
cout << "4. Exit" << endl;
cout << "*****************ANT ATM MACHINE*****************" << endl;
system("Color 0A");
}
void option() {
int option;
double balance = 1000;
double depositAmount, withdrawAmount;
do {
showMenu();
cout << "Option: ";
cin >> option;
system("cls");
switch (option) {
case 1:
cout << "Balance is: " << balance << "$" << endl << endl;
break;
case 2:
cout << "Deposit Amount: ";
cin >> depositAmount;
if (depositAmount >= 0) {
cout << endl;
balance = balance + depositAmount; //balance += depositAmount
}
else {
cout << "Cannot Deposit Negative Amount of Money!" << endl << endl;
}
break;
case 3:
cout << "Withdraw Amount: ";
cin >> withdrawAmount;
if (withdrawAmount <= balance) {
cout << endl;
balance = balance - withdrawAmount; //balance -= withdrawAmount
}
else {
cout << "Not Enough Money!" << endl << endl;
}
break;
}
} while (option != 4);
cout << "Thank you!!!" << endl;
}
int main() {
showLogin();
option();
return 0;
}