Thread: While statement

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    While statement

    Hey guys I am having trouble with my while statement:

    if (id >= 1 && id <= 499)
    {
    cout << "\nPlease enter hours worked: ";
    cin >> hrs;
    }
    while (id <= 0 && id >= 500)
    {
    clrscr ();
    cout << "\nYou must enter a valid ID from 1 through 499.";
    cout << "\nPlease enter hours worked: ";
    cin >> hrs;
    }

    How would I get the the while statement to loop? When I run it, it freezes up if, the ID is 0 or less, 500 or more.

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    I think you mean:

    while(id<=0 || id>=500)

    as id cant be both conditions at the same time.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > while (id <= 0 && id >= 500)
    ...
    > cin >> hrs;
    Inputting id would be a good idea, otherwise you'll never get out again
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    10

    thanx

    thanx guys.

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