loop questions

So we just started learning loops and were give an assignment. The instructor started us out with a few lines of code and I was able to figure it out with what he'd given us, but he started it with a "for" loop. I've used do-while loops in a few excersises but can't seem to figure out how to apply it to this. While it isn't necessary that I use a do-while loop for the assignment I'd really like to learn. Any hints or a point in the right direction would be sweet.

Code for the "for" loop is as follows:

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
32
33
34
35
#include <iostream>
using namespace std;

int main()
{
    int numExercises;
double totalScore=0;
    double pointsPossible=0;

    cout << "How many exercises to input?" << endl;
    cin >> numExercises;

    for (int i = 1; i <= numExercises; i++)
    {
        cout << "Score received for Exercise " << i << " ";
int score;
        cin >> score;
        totalScore += score;
        cout << "Total points possible for Exercise " << i << " ";
int points;
        cin >> points;
        pointsPossible += points;
}

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout << "Your total score is: " << totalScore << " out of :" << pointsPossible;
cout << " Or " << totalScore / pointsPossible * 100 << "%" << endl;

system("pause");

return 0;
}
The equivalent to the for loop would be:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    if (numExercises > 0)
    {
        int i = 1;
        do {
            cout << "Score received for Exercise " << i << " ";
            int score;
            cin >> score;
            totalScore += score;
            cout << "Total points possible for Exercise " << i << " ";
            int points;
            cin >> points;
            pointsPossible += points;

        } while (++i <= numExercises);
    }
Oh, wow. Thanks for ending my hours of frustration!! :-)
Topic archived. No new replies allowed.