Thread: need help with if statement

  1. #1
    Registered User
    Join Date
    Oct 2001

    need help with while,do while and for loop

    hello, here's my program and it keeps on reading a positive number until the user enters a zero and determines and outputs the largest number. My program runs fine. Now, I need to add a While, Do-Whie & For Loop! Any suggestions thanks!

    #include <stdio.h>
    int main(void)
    int num = 1;
    int temp = 1;

    while( num != 0)
    printf("Enter The Next Positive Number: \n\n");

    scanf("%i" , &num);

    if( num > temp )
    temp = num;

    } // end while loop, user pressed "0"

    printf("The Largest Number Was: %i !", temp);

    return 0;
    Last edited by ucme_me; 11-05-2001 at 06:50 AM.

  2. #2
    Registered User
    Join Date
    Aug 2001
    for the for loop, put a forever loop in main(), and break if 0 is entered.

    for a while loop, put a while loop in main that checks the number against zero.

    the do-while is basically the same as the while loop.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 02:57 AM
  3. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 07:18 AM
  4. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM