【发布时间】:2016-08-03 04:01:58
【问题描述】:
所以我正在尝试编写一个基本程序,要求用户输入除 5 以外的任何数字,并且在用户不输入数字 5 的 10 次迭代之后,我希望程序打印到屏幕上。 到目前为止,这是我的代码:
#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 次迭代时停止循环并输出到屏幕。
【问题讨论】:
-
用计数器跟踪..
-
如果用户在
while循环中输入5会发生什么? -
嘿路易斯! 欢迎来到 Stackoverflow !!! ...根据您的问题,我建议您检查 this 并至少选择两个选项,阅读它们,然后您可以回到这里询问您的问题..我们很乐意为您提供帮助:-)
标签: c++ loops while-loop