hai. anyone can help me ? I run my coding but it be invalid option even I already declare my coding. Can I know which part I wrong ?

#include <iostream>
#include <string>

using namespace std;

void printintromenu();
void login();
void mainmenu();

int main ()

    cout << "Welcome To ZS ATM" << endl << endl;
    char intro;
    cout << " ******************Welcome to ZS's ATM Machine*****************" << endl;
    cout << "l) Login" << endl;
    cout << "q) Quit" << endl;
    cin >> intro;

    if (intro=='l')
    else if (intro=='q')
        cout << "You have quit the program" << endl;

    return 0;


void login ()
        string id;
        string password;
        bool loginSuccess = false;

            cout << "\n\nPlease enter your user id: " << endl;
            cin >> id;
            cout << "\n\nPlease enter your password: " << endl;
            cin >> password;

            if (id == "zurena" && password == "zurena")
                cout << " Successful Login ";
                loginSuccess = true;

                cout << "**********LOGIN FAILED!**********\n\n";
                cout << "Please try to login again" << endl;


    while (!loginSuccess);

void mainmenu ()    
    char option;
    float balance, amount,withdraw;
    //Prompting user to select account type
    cout << "Access Granted ! " << endl;
   //Display account operations options to user
     cout << "d) Deposit Money" << endl;
     cout << "w) Withdraw Money" << endl;
     cout << "r) Request Balance" << endl;
     cout << "q) Quit" << endl;
     cout << "Select an option: ";
     cin >> option;

   //prompt user to select operation
    while (option!='d'|| option!='w' || option!='r' ) 
        if (option == 'd') // User want to Deposit money
            cout << "Please enter amount to deposit ";
            cin >> amount;
            cout << " The deposit amount you had entered is: RM" << amount << endl;
        else if (option=='r')
            cout << "Your balance is: RM " << balance << endl;

        else if(option == 'w') // User want to Withdraw money
           //prompt user to enter amount he/she want to Withdraw money
           cout << "Please enter amount to withdraw ";
           cin >> withdraw;
            cout << "You had withdraw: RM" << withdraw << endl;

        cout << "Invalid Option Selected. Please select the option given" << endl;
        cin >> option;

1 Year
Discussion Span
Last Post by thines01

1) It would be nice to have a do-loop around your login function so the user will be forced to login or quit
2) Inside "mainMenu()" the test for the option should be shortend to JUST ensure a correct choice is made. Once made, the program can drop down to respond to what the user chose.
3) The floats "amount" and "withdraw" should be moved inside the clauses that use them.
4) The float "balance" should be made static (this would work as long as you will only allow one user per run). This will allow it to retain value for balance checking later on.
5) Please initialize all of your variables to default values. This will aid in debugging.

There is more, but if you make these changes, some of the other ones will reveal themselves.

Edited by thines01: Forgot something.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.