什么问题?
c++吧
全部回复
仅看楼主
level 6
Lion1942 楼主
高手帮忙看看这段代码有什么问题,为什么执行后会出现“程序已停止工作”的错误提示?
#include <iostream>
using namespace std;
double ave(double values[],int count);
int main()
{
     const int number=10;
     double array[]={0};
     int i=0;
     char ch=0;
     do{
         cout<<"Please input a number!"
             <<endl;
         cin>>array[i++];
         cout<<"Do you want to input again?"
             <<endl;
         cin>>ch;
     }while(i<=number && ch=='y');
     if(i>number)
     {
         cout<<"Sorry,you can not input any more!"
             <<endl;
         exit(1);
     }
     double result=ave(array,i);
     cout<<"The result of these number's average is:"
         <<result
         <<endl;
     return 0;
}
double ave(double values[],int count)
{
         double sum=0;
         for(int j=0;j<=count;j++)
         {
             sum+=values[j];
         }
        
         return sum/count;
}

2010年08月16日 14点08分 1
level 7
array数组太小 只有一个数……
for(int j=0;j<=count;j++)改成j<count
2010年08月16日 15点08分 2
1