Search code examples
c++visual-c++undeclared-identifier

'If' identifier not found


I am a beginner C++ learner and I always have a problem on if loop in visual studio 2010

#include <iostream>
#include <string>
#include <fstream>
#include <conio.h>

using namespace std;

int main(void){

    string name;
    int money;

    cout << "Hello, Enter your name here: ";
    cin >> name;
    cout << "\n\nHello " << name << ".\n\n";

    cout << "\nEnter your salary here:L";
    cin >> money;

    If(money <= 50000 || money >= 100000 );
    {
        cout << "\nGood!\n";
        } else if(money >=49999){
               cout << "\nJust begin to work?\n"
               } else if(money <= 100000){
                      cout << "\nWow!, you're rich\n";
                      }else{
                            cout << "\nMillionaire\n";
                            }
    system("PAUSE");
    return 0;
}

And the compiler said 'If' identifier can not be found. Help needed please. Thanks

Baramee


Solution

  • if doesn't designate a loop, but a conditional. Note that it's lower-case if, as opposed to what you have - If.

    Also, you need to remove the trailing semicolon.

    This line:

    if(money <= 50000 || money >= 100000 );
    

    does nothing.

    The following:

    if(money <= 50000 || money >= 100000 ) //no semicolon here
    {
        cout << "\nGood!\n";
    } 
    else if(money >=49999)
    {
    }
    

    executes the first block if the condition is true.