我正在尝试编写一个程序,要求用户输入 0 到 1000000 之间的数字,并输出某个数字的出现(用户也输入)
我已经编写了这个程序,并且我相信它运行良好,但是我有一个问题是如果 while 表达式不正确,我想 cout 某个消息但我不知道将它放在哪里。
这是我的程序:
#include <iostream>
using namespace std;
int main()
{
int n,j=0,key;
cout << "Pleaser enter digits\n";
cin >> n;
cout << "please enter key number\n";
cin >> key;
while (n>0 && n<1000000)
{
if(n%10==key)j++;
n= n/10;
}
cout << "The number " << key << " was found " << j << " time(s)" << endl;
return 0;
}
提前致谢!