You're doing integer division at line 20.
Both sum and 6 are integers.
The integer division is done before being assigned to the float.
Is the problem not that hes adding everything to position 6 in the array ?
Surely the code should be
1 2 3 4 5
|
for (int count=0; count<age; count++)
{
sum+= a[count];
}
|
if it were
Age = 6
Therefore everything is added to postion 6 ?
edit: it would also be the same for
1 2 3 4 5
|
for (int count=0; count<age; count++)
{
cout <<"ENTER AGE "<< count<<" : ";
cin>>a[age];// should be cin >> a[count];
}
|
Last edited on
@jidder
Good catch. You're correct.
age
is certainly a poor choice of a name for an array limit.
Something like MAX_AGES would certainly have conveyed the meaning more clearly.
In both loops the OP should have been referring to a[count]