Using While Loop to write a program

This is a discussion on Using While Loop to write a program within the C++ Programming forums, part of the General Programming Boards category; How can i start the logic for this program is there a formula or do you all know where can ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    37

    Question Using While Loop to write a program

    How can i start the logic for this program is there a formula or do you all know where can i see a similar example, please.

    Program that uses the while loop to compute and print the sum of a given number of squares.

    Ex. If 5 is Input program will print 55

    I'm not asking to do this for me just want Ideas.

    I'm kind of slow at the beginning of evrything but at the end I'll never forget it.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The idea is given to you: "use the while loop to compute and print the sum of a given number of squares".

    So -- figure out the conditions on the while loop (i.e., when should it stop) and what computation needs to happen each step through.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    if x = something

    n := 0

    for each x

    n := n + x * x

    x := x - 1

    loop

    Right? I mean I know its sort of pseudo-code and sort of a hybrid between basic and pascal, but you get the picture. The trick is getting the input and having a second variable maintain the summation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C keep a loop going whilst program continues on
    By fortune2k in forum C Programming
    Replies: 6
    Last Post: 03-11-2009, 08:44 AM
  2. Replies: 8
    Last Post: 12-01-2008, 09:09 AM
  3. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  4. Need help with a loop program
    By hieugene in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2006, 02:42 AM
  5. Read a file into a loop program
    By TimeClock in forum C Programming
    Replies: 5
    Last Post: 07-17-2003, 06:29 PM

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