Thread: ATM C++ ERROR *expected primary expression before else*

  1. #1
    Registered User GrafixFairy's Avatar
    Join Date
    Mar 2014
    Posts
    45

    ATM C++ ERROR *expected primary expression before else*

    I keep getting an error here and cant quite figure out why, can someone help me please

    Code:
    else if (mainMenu == 3){
    
    
        cout << "Please make a selection" << endl
               << "    1) Withdraw from account" << endl
               << "    3) Back to main menu" << endl;
            cin >> withdrawMenu;
            
    if (withdrawMenu == 1){
                       
        cout << "Please Enter sum you wish to withdraw from account" << endl;
         cin >> withdraw;
                
         if ( withdraw > balance){          
    cout << "Value Exceeds Current balance Please enter new amount\n" << endl;
    cin >> withdraw;
               cout << " You Have Withdrawn " << withdraw << " From your Accout" << endl;
               balance = balance - withdraw;
               cout << " Balance is now " << balance << endl;
               }
               
         else {
                cout << " You Have Withdrawn " << withdraw << " From your Accout" << endl;
                balance = balance - withdraw;
                cout << " Balance is now " << balance << endl;
      
      }
                else if (withdrawMenu != 3) //<<<<<<<<<<<<here
                    {
                        cout << "Invalid entry. Try again" << endl;    
                    }
    
    
                } while (withdrawMenu != 3);
      
    }
    else if (mainMenu != 4)
            {
                cout << "Invalid entry. Try again \n\n";
            }
        } while (mainMenu != 4);
    
    
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Perhaps if you had some sensible indentation, you'd see it:

    Code:
    else if (mainMenu == 3){
    
    
      cout << "Please make a selection" << endl
        << "    1) Withdraw from account" << endl
        << "    3) Back to main menu" << endl;
      cin >> withdrawMenu;
            
      if (withdrawMenu == 1){
                       
        cout << "Please Enter sum you wish to withdraw from account" << endl;
        cin >> withdraw;
    
        if ( withdraw > balance){
          cout << "Value Exceeds Current balance Please enter new amount\n" << endl;
          cin >> withdraw;
          cout << " You Have Withdrawn " << withdraw << " From your Accout" << endl;
          balance = balance - withdraw;
          cout << " Balance is now " << balance << endl;
        } else {
          cout << " You Have Withdrawn " << withdraw << " From your Accout" << endl;
          balance = balance - withdraw;
          cout << " Balance is now " << balance << endl;
        } else if (withdrawMenu != 3) {
          cout << "Invalid entry. Try again" << endl;    
        }
      } while (withdrawMenu != 3);
    } else if (mainMenu != 4) {
      cout << "Invalid entry. Try again \n\n";
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error expected primary-expression before else eror
    By ReneeJA in forum C++ Programming
    Replies: 14
    Last Post: 02-28-2014, 01:57 PM
  2. error : expected primary-expression before ']' token
    By funnydarkvador in forum C Programming
    Replies: 8
    Last Post: 02-20-2013, 07:06 PM
  3. error : expected primary-expression before ']' token
    By funnydarkvador in forum C++ Programming
    Replies: 8
    Last Post: 02-20-2013, 07:06 PM
  4. Error: expected primary expression and ; before else
    By dragonfly22 in forum C++ Programming
    Replies: 5
    Last Post: 09-17-2012, 04:24 PM
  5. Replies: 24
    Last Post: 09-06-2006, 06:17 PM

Tags for this Thread