Problem in the last part of question !!!!!

The question is :
- Read 8 values from the user.
- Display the average of the values .
- Copy those (values < average) in another array .
-## Display the average of the second array .

It's not Displaying the correct average !!!!!!!!!!!!!!!!!

The code is :

#include<iostream>
using namespace std;
void main()
{
int valu1[8];
for(int i=0 ; i<8 ; i++)
{
cin>>valu1[i];
}

int sum = 0;
for(int i = 0; i < 8; i++)
{
sum += valu1[i];
}
int average = sum / 8;
cout<<average<<endl;

int valu2[8];
int count=0 ;
for (int j=0; j<8 ; j++)
{
if(valu1[j]< average)
{
valu2[count]= valu1[j];
count++;
}
}
int sum2 = 0;
for(int h = 0; h < 8; h++)
{
sum2 += valu2[h];
}
int average2 = sum2 / 8;
cout<<average2<<endl;
}
What do you mean that it doesn't display the correct average value? Maybe it's because you use integer. Try to use double type.
if(valu1[j]< average) ??????????
int sum2 = 0;
for(int h = 0; h < count; h++)
{
sum2 += valu2[h];
}
int average2 = sum2 / count;
cout<<average2<<endl;
Last edited on
Thank you mr vlad from moscow .
You gave me the correct answer ..
Topic archived. No new replies allowed.