Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;循环在第一次迭代时卡住_C++_Arrays - Fatal编程技术网

C++ C++;循环在第一次迭代时卡住

C++ C++;循环在第一次迭代时卡住,c++,arrays,C++,Arrays,我被指派制作一个程序,让用户将12个月的总降雨量输入一个双倍数组 该程序应计算并显示该年的总降雨量、月平均降雨量以及降雨量最高和最低的月份 我的教授要求我简单地修改她为我们提供的骨架。程序编译得很好问题是,在第一次迭代中,它显示第一个月,但在那里停止 不知道我做错了什么,有什么想法吗 这是相关区域的代码 void getMonthlyRainfalls(double rainfallsArr[], int size, int month){ cout << "Please type

我被指派制作一个程序,让用户将12个月的总降雨量输入一个双倍数组

该程序应计算并显示该年的总降雨量、月平均降雨量以及降雨量最高和最低的月份

我的教授要求我简单地修改她为我们提供的骨架。程序编译得很好问题是,在第一次迭代中,它显示第一个月,但在那里停止

不知道我做错了什么,有什么想法吗

这是相关区域的代码

void getMonthlyRainfalls(double rainfallsArr[], int size, int month){
 cout << "Please type the rainfalls occurring in the month " << (month+1) << ": " ;

 do{
  if (! cin){
     cin.clear();
     cin.ignore(1124, '\n');
  }

  for (int i = 0; i < size; i++)
      cin >> rainfallsArr[month];

  if (!cin || rainfallsArr[month] < 0)
      cout << "Please retype the rainfalls occurring in the month " << (month+1) << ": " ;
  } while (!cin || rainfallsArr[month] < 0);
 }
void getMonthlyRainfalls(双rainfallsArr[],整数大小,整数月){

这就是你作业的解决方案

#include <iostream>
using namespace std;
int main()
{
 double rain_fall[12] , maxi=0 , mini , sum=0; // maxi for the highest  
 //amount mini for the lowest
 for(int i=0; i<12; i++)
{
    cout<<"please enter the total amount of rainfall in the month number "
    <<i+1<< endl;
    cin>>rain_fall[i];
    if(i==0)
        mini=rain_fall[i];  // happened just once to give it an initial 
    value from the array
    if(maxi<rain_fall[i]) // the highest  amount
        maxi=rain_fall[i];
    else if (mini>rain_fall[i])
        mini=rain_fall[i];  // the lowest  amount
    sum+=rain_fall[i];
}
cout<<"the total amount in the year is : "<<sum<< endl;
cout<<"the average amount per month is : "<<sum/12<< endl;
cout<<"the highest  amount in the year is : "<<maxi<< endl;
cout<<"the lowest  amount in the year is : "<<mini<< endl;
return 0;
}
#包括
使用名称空间std;
int main()
{
双倍降雨[12],最大值=0,最小值,总和=0;//最大值为最高值
//最低限额的最低限额

对于(int i=0;iwhile(cin&rainfallsArr[month]>0)

为什么要循环大小时间来获取一个月的降雨量,并重复地将其存储在相同的位置,覆盖上一个位置?如果不是12,我不知道大小代表什么。如果每个月有多个降雨量总计,也许你应该在循环中添加值。这是一个我似乎无法解决的问题w要解决它,我知道问题出在for循环上,但我看不出哪里出了问题。我会去掉两个循环,但我仍然不确定大小。假设一年内每个月有一个值,然后删除
for(int i=0;i
这个答案缺少解释。我在上面写的。你能为你的答案提供更多的上下文吗?