Something wrong with my for loop?

I am writing a program where I need a for loop to run a certain amount of times, depending on user input.
int num will be entered by the user.
Everything is declared and no syntax errors, the counter just doesn't work.
I currently have this function:

double getScores(int num){
int i;
double score_total = 0;
double score;
for( i=0; i < num; i++){
cout << "counter: " << i << endl; // check to see if counters working
cout << "num: " << num << endl; //check if user input still holds true.
cout << "Enter your score: ";
cin >> score;
score_total = score_total + score;
}
return score_total;
}

everything works fine, I don't have any syntax errors. However when I compile the program, my cout statement shows the counter being at 0, all the time.

Lets say num is 3, the statement is printed out only twice and the counter remains at zero..

Can someone help me take a look at what might be wrong?
I compiled your function along with a simple main function and I think I'm getting the results you're expecting to see. Are you calling the getScores function differently?

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;

double getScores(int num){
    int i;
    double score_total = 0;
    double score;
    
    for( i=0; i < num; i++){
        cout << "counter: " << i << endl; // check to see if counters working
        cout << "num: " << num << endl; //check if user input still holds true.
        cout << "Enter your score: ";
        cin >> score;
        score_total = score_total + score;
    }
    
    return score_total;
}

int main()
{
    int number=3;

    cout << "main scores = " << getScores(number) << endl;
}
counter: 0
num: 3
Enter your score: 10
counter: 1
num: 3
Enter your score: 20
counter: 2
num: 3
Enter your score: 30
main scores = 60
Topic archived. No new replies allowed.