loops for sums

This is a discussion on loops for sums within the C++ Programming forums, part of the General Programming Boards category; How do i use loops to find the some of numbers taking from an external file. I already have the ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    17

    loops for sums

    How do i use loops to find the some of numbers taking from an external file.
    I already have the numbers listed on the screen, but i can't figure out how to show the sum of the numbers after the list.
    Please help

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    You have the numbers listed on the screen. So you know how to read them from the file. The only thing you need to do is after each time you've read a number, update a sum-variable. Such like this:

    Code:
    sum = 0
    while not end of file
        number = read number ()
        sum = sum + number

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, 01:01 PM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 01:18 AM
  3. recoursion or loops?
    By Mecnels in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2002, 12:09 PM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM
  5. for loops - newbie q's
    By Narciss in forum C Programming
    Replies: 8
    Last Post: 09-26-2001, 03:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21