2015-03-31 104 views
0

}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其余信息类型任何人都可以帮忙吗?我不知道如何解决它

回答

0

既然你使用<<endl;新行字符被留在buffer.This字符由follows.So删除那些<<endl;和代码应工作的CIN读细

+0

它没有工作:( – BrandoG 2015-03-31 17:16:10

0

首先你的安排非常糟糕。其次,你需要提供更多关于你想要实现的信息?你在第一个'cin'中输入了什么,使得它不会停止而直接进行?请注意,您已将int用于变量North和North,因此除数字以外的任何内容都将使程序显示“couts”的其余部分,并在未执行错误处理时终止。

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

我可以运行此代码没有任何问题。截图作为证明。

enter image description here

正如你从截图中可以看到,输入的数值没有在所有检查。我可以输入3代表1代表是的,2代表是否继续。包括您的if语句或您用来执行检查的任何方式,然后继续下一步。确保你清楚地说明了用户应该输入的输入。针对不同的标准有适当的变量类。

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