This make me crazy. Someone please.

Question 4:

Write a program to find how many students get mark more than average of quizzes of 30.
Done! What do I win?
Im just asking for someone that can help me. Not paid service. 😏
@DARKADVERSARY

Im just asking for someone that can help me.


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.

This is my code.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>

using namespace 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?
Compute the average after you've entered all the values.

You're computing a moving average at the moment.
But how can I do it? Because I need to compare the student mark with average
You need two loops. The first for calculate the average and the second to calculate the number of students above the average.
How to call back the mark that the user has entered for student 1, 2, 3, 4, & 5 ?
You need an array for mark.
Can you give me an example? :)
Btw thank you for your response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>

using namespace 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;
}
I got it. Thank you so much. Thanks, sir !! @coder777
Topic archived. No new replies allowed.