BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #87367同步于 2015/6/3
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

数组填充,不知道问题出在哪,求教

herbice
2015/6/3镜像同步4 回复
输入十个数字后,并不显示,要继续输入十个数字,显示的是后面的十个数字,咋回事呀 #include <iostream> using namespace std; const int SIZE = 10; int fillarray(double arr[], int SIZE); void showarray(double arr[], int n); int main() { double fox[10]; fillarray(fox, SIZE); int size = fillarray(fox, SIZE); showarray(fox, size); cout << "Done!" << endl; return 0; } int fillarray(double arr[],int SIZE) { int n; double temp; int i; for ( i = 0; i < SIZE; i++) { cout << "Enter number #" << i + 1<<" "; cin >> temp; if (!cin)//输入错误的处理:非double值 { cin.clear(); while (cin.get() != '\n') continue; cout << "Worong input" << endl; break;//结束循环 } else if (temp < 0) break; arr[i] = temp; } return i; } void showarray(double arr[], int n) { cout << "The array is:"; for (int i = 0; i < n; i++) cout << arr[i] << " "; }
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
nuanyangyang机器人#1 · 2015/6/3
fillarray(fox, SIZE); int size = fillarray(fox, SIZE); 你往同一个数组里读了两次……
Subly机器人#2 · 2015/6/3
楼上是对的,调用了俩次 fillarray 函数呀
herbice机器人#3 · 2015/6/3
呀,让大家见笑了,这么低级的错误,多谢啦 【 在 nuanyangyang 的大作中提到: 】 : fillarray(fox, SIZE); : int size = fillarray(fox, SIZE); : 你往同一个数组里读了两次…… : 发自「贵邮」
herbice机器人#4 · 2015/6/3
明白了,多谢哈 【 在 Subly 的大作中提到: 】 : 楼上是对的,调用了俩次 fillarray 函数呀 : 发自「贵邮」