C ++编码障碍

时间:2015-03-31 15:32:58

标签: visual-c++

}

int North, north;
cout << "You enter the forest, where would you like to go.\n" << endl;
cin >> North;

int Yes;
cout << "You appear in front of a cave, you see a sign saying. Canifis Cave BEWARE!\n" << endl;
cout << "Are you going to enter. (1.Yes/2.No?)\n" << endl;
cin >> Yes;


cout << "You enter the cave.. It is lit by torches only going westward. Are you going to follow the lit path? (Yes/No)\n" << endl;
cin >> Yes;


cout << "You see the the goblins.\n" << endl;
cout << "They are asleep and you see the Sword Of A Thousand Truths against the wall on a makeshift stand.\n" << endl;

int pickOption;
cout << "You can either kill the goblins by throwing a torch off the wall on them and retrieve the sword.\n";
    cout << "Or you can just quietly take it and leave\n" << endl;
    cout << "1 - Kill goblins with torch then take The Sword Of A Thousand Truths.\n" << endl;
    cout << "2 - Take The Sword Of A Thousand Truths quietly and leave.\n" << endl;
    cin >> pickOption;

    switch (pickOption)
    {
    case 1:
        cout << "The Goblins burned to death, congratulations!. you retrieve The Sword Of A Thousand Truths.\n" << endl;
        cout << "You make your way back to Doric and give him the family heirloom he thanks you.\n";
        cout << "You then leave and continue on your journey after finishing Doric's Quest.\n";
            cout << "CONGRATULATIONS ON COMPLETEING DORIC'S QUEST!!\n" << endl;
            break;

    case 2:
        cout << "You sneak by the goblins, retrieve the family heirloom and make your way out the cave unnoticed.\n" << endl;
        cout << "You make your way back to Doric and give him the family heirloom he thanks you.\n";
        cout << "You then leave and continue on your journey after finishing Doric's Quest.\n";
        cout << "CONGRATULATIONS ON COMPLETEING DORIC'S QUEST!!\n" << endl;
        break;
    }

    return 0;

}

在北部之后,它不允许您输入其他问题的cin,它只是跳过并发布所有cout信息,任何人都可以帮忙吗?我不知道如何解决它

2 个答案:

答案 0 :(得分:0)

由于您使用了<<endl;缓冲区中保留了新的行字符。此字符由后面的cin读取。删除那些<<endl;并且代码应该可以正常工作

答案 1 :(得分:0)

首先,你的安排非常糟糕。其次,您需要提供有关您要实现的目标的更多信息?你在第一个'cin'中输入了什么让它继续直接而不停止?请注意,您已使用int作为变量North和north,因此除了数字之外的任何内容都会使程序显示其余的'couts'并在没有实现错误处理时终止。

我认为您面临的问题是因为您输入字母而不是int输入的数字。

  

我可以毫无问题地运行此代码。证明截图。

enter image description here

从屏幕截图中可以看出,输入的值根本不会被检查。我可以输入3表示1表示是,2表示否,它仍然继续。包括您的if语句或用于执行检查的任何方式,然后继续执行下一步。确保清楚地说明用户应输入的输入。为不同的标准提供适当的变量类。

如果您不知道如何实现或完成此操作或需要进一步的帮助做评论。我将使用代码编辑这篇文章。