-2

我是初学者 C++ 学习者,我总是在 Visual Studio 2010 中的 if 循环上遇到问题

#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;
}

并且编译器说找不到'If'标识符。请帮助。谢谢

巴拉米

4

2 回答 2

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.

于 2012-02-19T21:18:31.153 回答
6

与许多编程语言一样,C++ 区分大小写。确保将其键入为if,而不是If

于 2012-02-19T21:16:25.020 回答