返回信息流#include <iostream>
#include <cctype>
int main()
{
using namespace std;
double donation[10];
int i = 0, count = 0;
double temp, sum = 0, average;
while (i < 10 && (cin >> temp) && !isdigit(temp))
{
donation[i] = temp;
sum += temp;
i++;
}
if (i != 0)
average = sum / i;
else
{
cout << "Please enter a number!" << endl;
}
for (int j = 0; j < i; j++)
{
if (donation[j]>average)
count++;
}
cout << "The average of those num is " << average << endl;
cout << "And there are " << count << " numbers bigger than average!" << endl;
return 0;
}
代码如上面,当输入大于48的时候就会跳出循环,这是为什么啊?
这是一条镜像帖。来源:北邮人论坛 / cpp / #81309同步于 2014/8/6
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
求助, C++ plus的课后题,莫名的跳出循环
vvmelone
2014/8/6镜像同步17 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
这样啊,谢谢啦,那要改的话要怎么改呢,要求遇到非数字字符终止。
【 在 nuanyangyang (暖羊羊) 的大作中提到: 】
: isdigit不接受double参数。
: 来自「北邮人论坛手机版」
通过『我邮2.0』发布
嗯,谢了,48只是我自己测试的时候试出来的
【 在 FromSixToTen (【意涵困】|【若晨困】|【贝由困】链域) 的大作中提到: 】
: isdigit(temp) 函数有问题,跟48无关.
通过『我邮2.0』发布
【 在 vvmelone 的大作中提到: 】
: 嗯,谢了,48只是我自己测试的时候试出来的
:
: 通过『我邮2.0』发布
把isdigit(temp)函数去掉就行啦,cin会帮你识别数据类型.
详情请见这一页,return value一节。 http://www.cplusplus.com/reference/istream/istream/operator%3E%3E/
英文的,压力好大。谢啦
【 在 nuanyangyang (暖羊羊) 的大作中提到: 】
: 详情请见这一页,return value一节。 http://www.cplusplus.com/reference/istream/istream/operator>>/
通过『我邮2.0』发布
膜拜一下,谢啦
【 在 FromSixToTen (【意涵困】|【若晨困】|【贝由困】链域) 的大作中提到: 】
: 把isdigit(temp)函数去掉就行啦,cin会帮你识别数据类型.
通过『我邮2.0』发布