Calculating N amount of assignments

The problem is as follows:

Write a program that calculates the total grade for N classroom exercises as a percentage. The user should input the value for N followed by each of the N scores and totals. Calculate the overall percentage (sum of the total points earned divided by the total points possible) and output it as a percentage. Sample input and output is shown below:

How many exercises to input? 3

Score received for exercise 1: 10
Total points possible for exercise 1: 10

Score received for exercise 2: 7
Total points possible for exercise 2: 12


Score received for exercise 3: 5
Total points possible for exercise 3: 8

Your total is 22 out of 30, or 73.33%.


I am not really sure how to make it cout how ever many exercises the user chooses. On top of that, how would I implement the user choosing the score they earned and the total score possible? Once I see how to do that part of the code I think I can figure out how to have it display the last line in the example containing their grade. I started to try to code this but really didn't know where to start.
1
2
3
4
5
6
7
8
9
10
11
     int numOfExercises;
     cout << "How many exercises to input? \n";
     cin >> numOfExercises;
     cout << "Score received for exercise 1: ";
     cout << "Total points possible for exercise 1: \n";
     
     cout << "Score received for exercise 2: ";
     cout << "Total points possible for exercise 2: \n";
     
     cout << "Score received for exercise 3: ";
     cout << "Total points possible for exercise 3: \n";
Dynamic memory was made specifically for this. Dynamic memory is used first by declaring a pointer. Then by using the operator new. So an example would be
1
2
int * points;
points = new int[numOfExercises];

Then when the program is run and you input the number of exercises the program will that create that many variables as a one dimensional array. Meaning you could access it by typing points[0] for the first value in points. You would then have to use a for loop to go through each time for each assignment which wouldn't really be that complicated. If you need to learn more about the operator new and how it works try http://www.cplusplus.com/doc/tutorial/dynamic/
Dynamic memory was made specifically for this.

No dynamic memory is need to solve this problem.


I am not really sure how to make it cout how ever many exercises the user chooses.

Use a loop.


On top of that, how would I implement the user choosing the score they earned and the total score possible?

Query the user for each. Get the user response. Add the responses to a running total of each.

Topic archived. No new replies allowed.