We can only help with what we can see of the coding you've done. So, show us what you have written, where you're having problems etc. Then, someone can help out, if they're so inclined. But, we don't write the program for you.
#include <iostream>
usingnamespace std;
int main()
{
int mark, student = 0;
int i, sum = 0;
double avg;
for(i=1; i <= 5; i++){
cout << "Enter the student " << i << " mark : ";
cin >> mark;
sum = sum + mark;
avg = sum / 5;
if(mark > avg) {
student++;
}
}
cout << "\nRESULT : ";
cout << "\n" << student << " student get mark more than the average of quiz." << endl;
return 0;
}
When I run my code with input: 10, 10, 10, 10, 1. I get the true answer which is 4 students that get marks more than average.
But when I run my code with input 80,50,30,65,47. I get wrong answers which are 3 students get marks more than the average of quizzes. Can you help me?
#include <iostream>
usingnamespace std;
int main()
{
int mark[5], student = 0; // Note: [5]
int i, sum = 0;
double avg;
for(i=0; i < 5; i++){ // Note: 0 <
cout << "Enter the student " << i << " mark : ";
cin >> mark[i]; // Note: [i]
sum = sum + mark[i]; // Note: [i]
// avg = sum / 5; // Move this after this loop
//if(mark[i] > avg) { // Make a second loop like this and move it there
//student++;
//}
}
cout << "\nRESULT : ";
cout << "\n" << student << " student get mark more than the average of quiz." << endl;
return 0;
}