2015-03-31 146 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語句或您用來執行檢查的任何方式,然後繼續下一步。確保你清楚地說明了用戶應該輸入的輸入。針對不同的標準有適當的變量類。

如果您不知道如何實現或完成此操作或需要進一步的幫助,請發表評論。我將用代碼編輯這篇文章。