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?