【发布时间】:2013-11-20 20:36:29
【问题描述】:
我们应该创建一个接受 15 个电话号码的程序。所有数字由 8 位数字组成。固定线路以 17 开头,移动线路以 39 开头。Prog 应计算固定线路和移动线路的数量。 此外,当用户输入负数时,prog 应该停止。
这是我的代码:
#include <iostream>
using namespace std;
void main ()
{
int n, c=1, cm=0, cf=0;
cout << "Enter a telephone number or enter a negative number to stop ";
while (c <= 15){
cin >> n;
if (n/1000000 == 39){
c++;
cm++;
}
else if (n/1000000 == 17){
c++;
cf++;
}
else cout << "Wrong telephone number" << endl;
cout << "Enter the next telephone number or enter a negative number to stop ";
cin >> n;
}
cout << "The number of fixed lines is " << cf << endl;
cout << "The number of mobile lines is " << cm << endl;
system ("PAUSE");
}
我有两个问题:
不知道用户输入负数时如何结束程序。
在输入第二个号码后,程序不会“输入下一个电话号码或输入负数停止”。
【问题讨论】:
标签: c++ visual-studio loops