ATM Simulator based on ATM Simulation by Kevin Oliver. Please tell me what you think. Constructive criticism is appreciated.
DOWNLOAD:
http://www.mediafire.com/file/5w48ubeoebtf3xc/ATM_Sim_OSX.zip
CODE:
// ATM SIMULATOR
// By Yung$cared
// Based On ATM Simulation by Kevin Oliver
// To make program function on windows/linux change system("clear")
#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>
using namespace std;
int balance;
string accountName;
string accountPass;
int accountNum;
bool loggedIn = false;
bool checked = false;
int main();
void flogin();
void fregister();
//Deposit Money
void fdeposit()
{
ofstream accountFile;
cout << "Enter the amount to be deposited" << endl;
cout << "$";
float amountdeposited = 0.00;
cin >> amountdeposited;
balance += amountdeposited;
accountFile.open("account.txt");
accountFile << accountName << endl;
accountFile << accountPass << endl;
accountFile << accountNum << endl;
accountFile << balance << endl;
accountFile.close();
cout << endl;
cout << "You deposited $" << amountdeposited << endl;
cout << "New balance $" << balance << endl;
cin.get();
cin.get();
main();
}
//Withdraw Money
void fwithdraw()
{
ofstream accountFile;
cout << "Enter the amount to be withdrawn" << endl;
cout << "$";
int amountwithdrawn = 0;
cin >> amountwithdrawn;
if (amountwithdrawn < 20)
{
cout << "Amount to withdraw must be greater than $20." << endl;
fwithdraw();
}
if(amountwithdrawn > balance){
cout << "Amount to be withdrawn is greater than your balance." << endl;
cin.get();
cin.get();
fwithdraw();
}
balance -= amountwithdrawn;
accountFile.open("account.txt");
accountFile << accountName << endl;
accountFile << accountPass << endl;
accountFile << accountNum << endl;
accountFile << balance << endl;
accountFile.close();
cout << "New balance $" << balance;
cin.get();
cin.get();
main();
}
//Check balance
void fbalance(){
cout << "Your balance is $" << balance;
cin.get();
cin.get();
main();
}
//Start
void startup(){
system("clear");
cout << "ATM_OS" << endl;
enum menuoptions {login = 1, freg = 2};
cout << "Press the corresponding number to access an option" << endl;
cout << "1. Login" << endl;
cout << "2. Register" << endl;
int choice = 0;
cin >> choice;
if(choice == login){
flogin();
}
if(choice == freg){
fregister();
}
if(choice != login && choice != freg){
cout << "Invalid Option." << endl;
cin.get();
cin.get();
main();
}
}
//Login
void flogin(){
system("clear");
ifstream accountFile;
accountFile.open("account.txt");
string line;
cout << "Login" << endl;
cout << "Username: ";
cin >> accountName;
cout << "Password: ";
cin >> accountPass;
//Check if account matches file
while(getline(accountFile, line)){
if(line == accountName){
while(getline(accountFile, line)){
if(line == accountPass){
cout << "Successful Login." << endl;
cin.get();
cin.get();
loggedIn = true;
accountFile.close();
main();
}
}
}
}
cout << "Unsuccessful Login." << endl;
cin.get();
cin.get();
if(accountFile)
accountFile.close();
flogin();
}
//Register
void fregister(){
string tempPass;
ofstream accountFile;
system("clear");
cout << "Register" << endl;
cout << "Username: ";
cin >> accountName;
cout << "Password: ";
cin >> accountPass;
cout << "Confirm Password: ";
cin >> tempPass;
if(accountPass != tempPass){
cout << "Passwords didn't match." << endl;
cin.get();
cin.get();
fregister();
}
//Create account
if(accountPass == tempPass){
balance = 0;
accountNum = rand() % 5000 + 1000;
accountFile.open("account.txt");
accountFile << accountName << endl;
accountFile << accountPass << endl;
accountFile << accountNum << endl;
accountFile << balance << endl;
accountFile.close();
cout << "Register successful.";
cin.get();
cin.get();
flogin();
}
}
//Check ID and Balance
void fCheck(){
system("clear");
ifstream accountFile;
string line;
string line2;
accountFile.open("account.txt");
bool tempcheck = false;
while(getline(accountFile, line)){
if(line != accountName && line != accountPass && line != " " && !tempcheck){
string temp = line;
int temp1 = atoi(temp.c_str());
if(temp1 != 0){
accountNum = temp1;
}
tempcheck = true;
}
}
accountFile.close();
accountFile.open("account.txt");
while(getline(accountFile, line2)){
string tempAccountNum = to_string(accountNum);
if(line2 != accountName && line2 != accountPass && line2 != " " && line2 != tempAccountNum ){
string temp = line2;
int temp1 = atoi(temp.c_str());
if(temp1 != 0)
balance = temp1;
}
}
accountFile.close();
checked = true;
}
//Main
int main()
{
if(!loggedIn){
startup();
}
if(!checked){
fCheck();
}
system("clear");
cout << "ID = " << accountNum;
cout << " NAME = " << accountName << endl;
enum menuoptions { deposit = 1, withdraw = 2, balance = 3, logout = 4};
cout << " Press the corresponding number to access an option\n";
cout << "1. Deposit money" << endl;
cout << "2. Withdraw money" << endl;
cout << "3. Balance Inquiry" << endl;
cout << "4. Logout" << endl;
int choice = 0;
cin >> choice;
if (choice == deposit)
fdeposit();
if (choice == withdraw)
fwithdraw();
if (choice == balance)
fbalance();
if (choice == logout){
loggedIn = false;
main();
}
//Catches if a choice that doesn't exist is entered. Doesn't stop strings from being entered
if(choice != deposit && choice != withdraw && choice != balance && choice != logout){
cout << "Invalid Option. " << endl;
cin.get();
cin.get();
main();
}
return 0;
}