I NEED URGENT HELP?!?!?

closed account (z6f9LyTq)
During a loop (for loop), say the user inputs a number and the loop repeated itself the number of ti.es the user inputed. During these repeats, the user inputs more data. How do I use every individual piece of data? For EXAMPLE, say the program asks a teacher to input the number of tests she has to grade. She says 5, it runs 5 times asking to input the grade, she puts 100, 90, 85, 76, 80. How would I add all these grades together for maybe an average?

It's probably something simple since I'm a beginner, nothing too fancy

PLEASE HELP. THANKS. XOXO
you could just create a variable called total or something and have a variable average where all the grades added up in total are then divided by number of tests.

i cant figure out my project right now so here's how you'd do yours:

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
#include <iostream>

using namespace std;

int main() {

int score;
int numTests;
int total=0;
double averager;

cout << "how many tests scores are there? ";
cin >> numTests;

for (int i=0; i<numTests;i++) {
    cout << "test #" << i + 1 << ": ";
    cin >> score;
    total+=score;
}

cout << "Total scores: " << total;
averager=total/numTests;
cout << "\nAverage of scores: " << averager;
return 0;
}
Last edited on
Topic archived. No new replies allowed.