ATM Machine.

I need help with the logic, and also I want all of the functions to read from my class which is called ATM. I also need help with reading it from main.cpp


#include <iostream>
#include <iomanip>
using namespace std;

//Function prototypes
void showMenu();
int mainMenuSelection(int);
void welcomeScreen();
double enterAmountScreen(double);

int main ()
{
//Declare variables
int choice;
//Set the numeric output formatting
cout << fixed << showpoint << setprecision(2);
//Function for welcome screen
welcomeScreen();
//Create a do\while loop
do
{
//Display the menu and get the user's choice.
showMenu();
cin >> choice;
//Validate the menu selection.
while (choice < 1 || choice > 5)
{
cout << "Please enter 1, 2, 3, 4, or 5: ";
cin >> choice;
}
//Function to choose in the main menu selection
mainMenuSelection(choice);
} while (choice != 5);
return 0;
}
//Function to show the main menu
void showMenu()
{
//Display the main menu screen
cout << endl << "\t\tMain Menu Screen" << endl << endl;
cout << "1) Withdrawal" << endl;
cout << "2) Deposit" << endl;
cout << "3) Check Balance" << endl;
cout << "4) Funds Transfer" << endl;
cout << "5) Exit ATM" << endl << endl;
cout << "Enter your choice: ";
}
//Function to choose in the main menu screen
int mainMenuSelection(int choice)
{
//Declare variables in mainMenuSelection
int withdrawChoice,
depositChoice,
checkBalanceChoice,
fundsTransferChoice;
double money = 0.0;
//Respond to user's menu selection
switch (choice)
{
case 1:
do
{
cout <<"\t\tWithdrawal Screen" << endl << endl;
cout << "1) From Checking" << endl;
cout << "2) From Savings" << endl;
cout << "3) Quick Cash" << endl;
cout << "4) Back to Main Menu" << endl;
cout << "Enter your withdraw choice: ";
cin >> withdrawChoice;
while (withdrawChoice < 1 || withdrawChoice > 4)
{
cout << "Please reenter 1, 2, 3, 4: ";
cin >> withdrawChoice;
}
enterAmountScreen(money);
} while (choice != 4);
//Back to main menu option
if (choice == 4)
{
showMenu();
}
break;
case 2:
do
{
cout <<"\t\tDeposit Screen" << endl << endl;
cout << "1) To Checking" << endl;
cout << "2) To Savings" << endl;
cout << "3) Back to Main Menu" << endl;
cout << "Enter your deposit choice: ";
cin >> depositChoice;
while (depositChoice < 1 || depositChoice > 3)
{
cout << "Please reenter 1, 2, or 3: ";
cin >> depositChoice;
}
enterAmountScreen(money);
} while (choice != 3);
//Back to main menu option
if (choice == 3)
{
showMenu();
}
break;
case 3:
do
{
cout << "\t\tCheck Balance Screen" << endl << endl;
cout << "1) From Checking" << endl;
cout << "2) From Savings" << endl;
cout << "3) Back to Main Menu" << endl;
cout << "Enter Your Check Balance Choice: ";
cin >> checkBalanceChoice;
while (checkBalanceChoice < 1 || checkBalanceChoice > 3)
{
cout << "Please reenter 1, 2, or 3: ";
cin >> checkBalanceChoice;
}
} while (choice != 3);
//Back to main menu option
if (choice ==3)
{
showMenu();
}
break;
case 4:
do
{
cout << "\t\tFunds Transfer Screen" << endl << endl;
cout << "1) From Savings to Checking" << endl;
cout << "2) From Checking to Savings" << endl;
cout << "3) Back to Main Menu" << endl;
cout << "Enter Your Funds Transfer Choice: ";
cin >> fundsTransferChoice;
while (fundsTransferChoice < 1 || fundsTransferChoice > 3)
{
cout << "Please reenter 1, 2, or 3: ";
cin >> fundsTransferChoice;
}
enterAmountScreen(money);
} while (choice != 3);
//Back to main menu option
if (choice == 3)
{
showMenu();
}
break;
case 5:
cout << "Program ending." << endl << endl;
break;
}
return choice;
}
//Function to display the welcome screen
void welcomeScreen()
{
cout << "Hit enter to simulate inserting card";
//Hit enter to go to the next screen
cin.get();
}
//Function to enter amount screen
double enterAmountScreen(double money)
{
int decision;
cout << endl << "\t\tEnter Amount Screen" << endl;
cout << "1) Enter Amount:";
cout << endl << "2) Back to Main Menu:";
cout << endl << "Enter your decision for the amount screen: ";
cin >> decision;
if (decision == 2)
{
showMenu();
}
else
{
cout << "Please enter the amount: ";
cin >> money;
}
return money;
}
Last edited on
Topic archived. No new replies allowed.