Hi!
I have understand arrays a little bit. But the problem, I am dealing with requires to count the entries when they are entered by the user , which then defines the size of array. The problem then demands to find the sum and average.
I have made the code as per my knowledge.But it's not working.
Help!
#include<iostream>
using namespace std;
int main()
{
int i, count;
double grade[count] ,average,sum;
for(i=0;grade[i]>=0;i++)
{ if(grade[i]>=0)
{
cout<<"Grade "<<i+1<<": ";
cout<<grade[i];
count++;
}
else
break;
}
for(i=0,sum=0;i<count;i++)
{
sum=sum+grade[i];
}
average=sum/count;
The size of Array is making trouble. The problem states:"... reads a list of double-precision
grades from the keyboard into an array named grade. The grades are to be counted as they’re
read, and entry is to be terminated when a negative value has been entered."
So here what I understand is The size of arrays will be determined by the number of entries.
Yes you're trying to create the array BEFORE you know how big it needs to be. Do you see a problem there? Do you understand that you need to know how big to make an array before you make it?