所以我想寫一個基本程序,要求用戶輸入除5以外的任何數字,並且在10次迭代用戶未輸入數字5之後,我希望程序打印向屏幕。 這裏是我到目前爲止的代碼:C++:雖然循環次數
#include <iostream>
#include <string>
using namespace std;
int main(){
int num;
cout << "Please enter a number other than 5." << endl;
cin >> num;
while (num != 5){
cout << "Please enter a number other than 5." << endl;
cin >> num;
}
return 0;
}
我只是不知道如何告訴計算機停止在10次迭代循環並輸出到屏幕上。
跟蹤計數器.. – Li357
如果用戶在while循環中輸入5,會發生什麼情況? –
嘿路易斯! **歡迎來到Stackoverflow !!! ** ...從你的問題,我會建議你請檢查[**此**](http://stackoverflow.com/questions/388242/the-definitive-c-書籍指南和列表),並至少做兩個選擇,閱讀它們,然後你可以回到這裏問你的問題。我們將非常樂意幫助你:-) – WhiZTiM