0

Write a program that prompts the use for the number of assignments in a specific class. Then using a for loop, prompt for each score. Use an accumulator to store the sum of the assignments, and then calculate the average score for the assignments.
HELP. I have no idea what's going on.

#include <iostream>

using std::cout;
using std::cin;

int main ()
{
    int number = 0,
        percent = 0;

    cout << "Enter number of assignments: ";
    cin >> number;

    for ( int assignments = 0; assignments < 5; assignments++ )
    {
        cout << "Enter percentage of assignment which you did correctly. Assignment " << assignments + 1 << ": ";
        cin >> percent;

        assignments += percent;
    }

    return 0;
}

Edited by Emma_3

2
Contributors
1
Reply
13
Views
3 Years
Discussion Span
Last Post by cgeier
1

Try writing the problem out in steps first. You can use pseudo-code (a combination of written language and computer language).

Prompt for number of assignments - "numAssignments"

for each assignment {
    Prompt for score - "enteredScore"

    totalScore = totalScore + enteredScore
}

averageScore = ....

Now convert that into code.
How do you write a proper for loop in C++? Convert the pseudo-code to a C++ for loop.

example data:
Score 1: 92
Score 2: 85
Score 3: 95

Using what I have above.

numAssignments = 3

How many assignments do you need to prompt for scores?
How can you write that in a for loop? Write it out on paper plugging in the values.

Edited by cgeier

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.