While statement

This is a discussion on While statement within the C++ Programming forums, part of the General Programming Boards category; Hey guys I am having trouble with my while statement: if (id >= 1 && id <= 499) { cout ...

  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
    523
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,544
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 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