注册 登录
编程论坛 C++教室

为何读取到字符的时候就结束了

hffjhhh 发布于 2020-09-20 02:58, 1739 次点击
比如输入2 d
为何读取到d的时候就退出for循环了?
程序代码:
#include<iostream>
int main(){
    using namespace std;
    double a[10];
    int i,count;
    count=0;
    double sum,c,as;
    sum=0;
    for(i=0;i<10;i++){
        cin>>a[i];
        sum+=a[i];
    }
    c=sum/i;
    for(i=0;i<10;i++){
        if(a[i]>c)
            count++;
    }
    cout<<"平均值为:"<<c<<endl<<"大于平均值的数字有:"<<count<<"";
    return 0;
}
3 回复
#2
apull2020-09-20 11:34
输入类型错误
#3
Link2Points2020-09-20 12:48
#4
Jonny02012020-09-20 15:40
stream 中出现错误的话, 就没有办法继续使用
必须重新设定状态
1