-2

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

LihO
  • 41,190
  • 11
  • 99
  • 167
santhods
  • 34
  • 5

2 Answers2

7

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.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
6

C++, like many programming languages, is case-sensitive. Make sure you type it as if, not If.

Dirk
  • 30,623
  • 8
  • 82
  • 102
reuben
  • 3,360
  • 23
  • 28