我正在製作一個使用if else語句的小程序,但不是使用數字來控制流程,而是希望能夠使控制工作與是和否;使用用戶輸入如YES和NO來控制C++中的程序流程
例如:
cout << "would you like to continue?" << endl;
cout << "\nYES or NO" << endl;
int input =0;
cin >> input;
string Yes = "YES";
string No = "NO";
if (input == no)
{
cout << "testone" << endl;
}
if (input == yes)
{
cout << "test two" << endl;
//the rest of the program goes here i guess?
}
else
{
cout << "you entered the wrong thing, start again" << endl;
//maybe some type of loop structure to go back
}
,但我似乎無法得到這部分的任何變化的工作,我可以讓用戶輸入一個0或1,而不是,但似乎真的愚蠢,我寧願它儘可能的自然,用戶不會說數字嗎?
也是我需要能夠簡單地添加更多的單詞,例如「不,不,野應否N」一切就一定意味着沒有
希望這有一定道理
也是我很想使用一個窗口,但我只學到了基本的C++到目前爲止,甚至沒有,我無法找到任何有關基本Windows編程的好資源。
這不是Windows編程。這只是標準的,獨立於平臺的C++。我建議你閱讀任何初學C++的書,而不要去看Windows編程教程。 – 2010-10-31 11:53:27