Thread: Loops

  1. #1


    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

  2. #2
    Registered User
    Join Date
    Apr 2002
    Without looking at the source it's a little difficult to help you out. Here is the syntax for a basic while loop.

    while( condition ) // example: while( bDone == false )
         // Execute
         // These
         // Statements
    Alternatively, if you know the exact number of iterations try a for loop.
    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.

    for( int i = 0; i < 5; i++ )
         // Foo
    Hope this helped a little.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple thread for loops
    By lehe in forum C++ Programming
    Replies: 12
    Last Post: 03-29-2009, 12:01 PM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 12:18 AM
  3. recoursion or loops?
    By Mecnels in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2002, 11:09 AM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 03:28 PM
  5. for loops - newbie q's
    By Narciss in forum C Programming
    Replies: 8
    Last Post: 09-26-2001, 02:44 AM