如果陈述不排除文字行?

时间:2018-09-28 19:40:16

标签: c++

此代码应在“如果(选择)是什么?”中要求输入 而这部分。但一旦输入答案为“提供执行代码段或跳过该代码段的能力”。结果应该是“正确!”但是它要么要求按键结束,要么重新询问问题。有人对我如何解决这个问题有建议吗?

srand((unsigned)time(0));
int random_interger;
int lowest = 2, highest = 18;
int range = (highest - lowest) + 1;
for (int index = 0; index < 20; index++) {
    random_interger = lowest + int(range*rand() / (RAND_MAX + 1.0));


if (random_interger == IF) {
        cout << " What is If (selection)?" << endl;
        cin >> IFs;



if (IFs == "Provides the ability to either do a block of code or 
skip that block of code.") {
            cout << "Correct!" << endl;

        }

1 个答案:

答案 0 :(得分:3)

string IFs;
cin >> IFs; 

即使用户准确键入了您期望的长行(他不会),这也不起作用。 cin >>变成一个字符串只会读一个字。您只会得到“提供者”。

查找getline API。但是即使那样,我仍然怀疑有人会准确键入这些行。

相关问题