-
Loops
I made a program that reads golf scores and pars from a file.
It then assigns the appropriate comment depending on the score.
Everything works fine, but I also need the sum of all the scores.
How do I use a loop to read the file again and add the scores and return their sum.
Any help would be appreciated
Thankyou
-
Without looking at the source it's a little difficult to help you out. Here is the syntax for a basic while loop.
Code:
while( condition ) // example: while( bDone == false )
{
// Execute
// These
// Statements
}
Alternatively, if you know the exact number of iterations try a for loop.
Code:
for( variable x; condition; increment )
{
// Do this
}
If you knew you wanted to loop 5 times you could do this. All this does is says while i is less than 5 keep executing code, and i++ simply increments the variable i AFTER the last line of code. If you want i to increment first, simply change i++ to ++i.
Code:
for( int i = 0; i < 5; i++ )
{
// Foo
}
Hope this helped a little.