I have to build a program which simulates an ATM Machine. I'm pretty sure that I have the code all figured out but I keep getting one error msg illegal else without if.
#include <iostream>
using namespace std;
int main()
{
double savingsmoney = 0;
double checkingmoney = 0;
int xinput_deposit;
int xinput_main;
int xinput_dollar=0;
cout << "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
cout << "Welcome to MyBank ATM" << endl;
cout << "Your Friend in the Market" << endl;
cout << "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl;
cout << "1 Deposit Money" << endl;
cout << "2 Check the Balance" << endl;
cout << "3 Exit" << endl;
cin >> xinput_main;
while (xinput_main != 3)
{
if (xinput_main == 1)
{
cout << " 1 Deposit into Checking" << endl;
cout << " 2 Deposit into Savings" << endl;
cout << " 3 Back to Main menu" << endl;
cin >> xinput_deposit;
}
while (xinput_deposit != 3)
{
if (xinput_deposit == 1)
{
cout << "Please Enter Dollar Amount = " << endl;
cin >> xinput_dollar;
checkingmoney = checkingmoney + xinput_dollar;
xinput_dollar = 0;
cout << " 1 Deposit into Checking" << endl;
cout << " 2 Deposit into Savings" << endl;
cout << " 3 Back to Main menu" << endl;
cin >> xinput_deposit;
}
else if (xinput_deposit == 2)
{
cout << "Please enter dollar amount = ";
cin >> xinput_dollar;
savingsmoney = savingsmoney + xinput_dollar;
xinput_dollar = 0;
cout << " 1 Deposit into Checking" << endl;
cout << " 2 Deposit into Savings" << endl;
cout << " 3 Back to Main menu" << endl;
cin >> xinput_deposit;
}
else
{
cout << "Invalid Entry!.. Try again" << endl;
cout << "1 Deposit into Checking" << endl;
cout << "2 Deposit into Savings" << endl;
cout << "3 Back to Main Menu" << endl;
}
cout << "====================================" << endl;
cout << "Thank you for your business Today" << endl;
cout << "Hope to see you sometime soon..Bye" <<endl;
}
system ("pause");
return 0;
}
The line with the ***** is where I am getting the error msg. Can anyone help me out????
My proffessor gave us a hint page where we need to use a while loop within a while loop in order for the program to run correctly.
doesn't the following line of code satisify the If for the else if statement???
if (xinput_main == 1)
{
cout << " 1 Deposit into Checking" << endl;
cout << " 2 Deposit into Savings" << endl;
cout << " 3 Back to Main menu" << endl;
cin >> xinput_deposit;