need help with if statement

This is a discussion on need help with if statement within the C Programming forums, part of the General Programming Boards category; hello, here's my program and it keeps on reading a positive number until the user enters a zero and determines ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    24

    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 05:50 AM.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    202
    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.

    starX
    www.axisoftime.com

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, 06:18 AM
  4. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 01: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, 03:49 PM

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