开发者

C++ | Syntax Error: Identifier 'i'

Hey guys, I'm pretty sure someone else has had this problem too, but I just couldn't find any related problems. This is also probably something really stupid like a typo or something, but I'm not able to figure it out >.<

What's wrong with the code, I always get this error:

error C2061: syntax error : identifier 'i'

#include <iostream>
#include <string>
using namespace std;

class MahinLuokka {
    public:
        void setNum(int);
        int getNum();
    private:
        int mahi_num;
};

int main()
{
    int i;
    do {
        cout << "Insert number between 1-100" << endl;
        cin >> i;
    } while i > 100 || i < 0;
    MahinLuokka mahi;
    mahi.setNum(i);
    cout << mahi.getNum() << endl;
    mahi.setNum(5);
    cout << "mahi_num set to 5" << endl;
    cout << mahi.getNum() << endl;

    // end
    int x;
    cin >> x;
    return 0;
}

void MahinLuokka::setNum(int number)
{
    mahi_num = numb开发者_运维知识库er;
}

int MahinLuokka::getNum()
{
    return mahi_num;
}


You need to enclose the conditions in parentheses. In other words, change this:

} while i > 100 || i < 0;

To this:

} while(i > 100 || i < 0);


while requires a (, so it should be while (i > 100 || i < 0);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜