[/code]ive just started learning C++ at college and ive got this task to which means i have to create a program of how an actual ATM bank works. So far ive come up with this
#include <iostream>
#include <string>
#include <windows.h>
usingnamespace std;
int main(){
int menuChoice=0;
int PIN=1234; //PIN is the name of the variable
bool pin=true;
bool isLooping = false;
cout<<"\n\tWelcome and please insert your card"<<endl<<endl;
Sleep(1500);
system("CLS");
while(isLooping==false){
cout<<"\n\tEnter your PIN"<<endl;
cin>>PIN;
system("CLS");
if(PIN == 1234){
cout<<"\t\nPlease choose one of the following options:"<<endl<<endl;
cout<<"\t\n 1.Cash Out"<<endl;
cout<<"\t\n 2.Statement"<<endl;
cout<<"\t\n 3.Other options"<<endl;
cin>>menuChoice;
isLooping = true;
system("CLS");
}
elseif (PIN>=false){
cout<<"\n\tIncorrect"<<endl;
}
if(menuChoice==1){
cout<<"\n\tYour balance today is: 9999.99\t"<<endl;
Sleep(1500);
cout<<"\n\tContinue?"<<endl;
cout<<"\n\t >> 1.Yes <<"<<endl;
cout<<"\n\t >> 2.No <<"<<endl;
cin>>menuChoice;
system("CLS");
if(menuChoice==1)
{
cout<<"\n\t >>Withdraw Amount<<"<<endl;
Sleep(1000);
cout<<"\n\t\t 1.5 Pounds"<<endl;
Sleep(200);
cout<<"\n\t\t 2.10 Pounds"<<endl;
Sleep(200);
cout<<"\n\t\t 3.20 Pounds"<<endl;
Sleep(200);
cout<<"\n\t\t 4.30 Pounds"<<endl;
Sleep(200);
cout<<"\n\t\t 5.40 Pounds"<<endl;
Sleep(200);
cout<<"\n\t\t 6.Triple Digit Value(000's)"<<endl;
Sleep(2000);
}
if(menuChoice==2)
{
cout<<"\n\t Thank You for using our services"<<endl;
system("\n\tpause");
//cin>>menuChoice;
}
return 0;
}
if(menuChoice==2){
cout<<"\n\tPrinting Statement"<<endl;
Sleep(1500);
cout<<"\n\tPrinting Complete"<<endl;
Sleep(1500);
cout<<"\n\tContinue?"<<endl;
cout<<"\n\t 1.Yes"<<endl;
cout<<"\n\t 2.No"<<endl;
cin>>menuChoice;
system("CLS");
/*if(menuChoice==1){
cout<<"\t\nPlease choose one of the following options:"<<endl<<endl;
cout<<"\t\n 1.Cash Out"<<endl;
cout<<"\t\n 2.Statement"<<endl;
cout<<"\t\n 3.Other options"<<endl;
cin>>menuChoice;
//isLooping = true;//
system("CLS");
}*/
}
}
cin.get();
cin.get();
}
/*
while(){
}
} */
what i want to do is after the part where it says continue and you either press 1 or 2 it should take you back to the main menu instead of having to recode everything again.
i know i need to use some sort of a loop but i dnt know how...any ideas??? also can you guys make it quite easy to understand.
Can you recopy your code back here into code tags so it is not a pain to look at >.<?
hey are at the bottom, and they end up as: [codea] Your code goes here [/codea], but without the a's in them.
I think what devonrevenge is trying to say is use a switch statement that has a case for each menu option. From each case call a function that carries out that menu option. That will cut down on repeatedly testing the menu option variable.
#include <iostream>
#include <locale> //need this for std::toupper
//using namespace std <--- don't do this
using std::cin; //either do this, or put std:: before each std thing
using std::cout; //I do this for things used a lot
using std::endl; //then use std:: for things that are not
//Put function declarations for each menu option here
int main() {
bool Quit = false;
char answer = 'N';
while(!Quit) {
//your code here
//function to show the menu
//get the menu option
//switch statement to process menu options
cout << "Do you want to Quit? Y or N" << endl;
cin >> answer;
answer = std::toupper(answer); //avoids testing answer twice
if(answer == 'Y') //test variable once
Quit = true;
}
return 0; //if all is well, something else if not
} //end of main
//definitions of functions here