Breaking while loop with CIN

This is a discussion on Breaking while loop with CIN within the C++ Programming forums, part of the General Programming Boards category; If I made a while loop like this: Code: while (seconds > 0) { system("CLS"); seconds = (seconds - 0.1); ...

  1. #1
    Registered User muffinman8641's Avatar
    Join Date
    Feb 2011
    Location
    Eastern-Central PA
    Posts
    76

    Breaking while loop with CIN

    If I made a while loop like this:
    Code:
    while (seconds > 0) {
              system("CLS");
              seconds = (seconds - 0.1);
              cout << setprecision(1) << fixed << seconds;
              Sleep(100);
    ...how could I set it up so that someone entering a letter below it (yes, I know about string and all that) broke the loop? Right now, I have this within the braces right below Sleep(100)...
    Code:
          if (letter == "w") {
            level++;
            break;
    ...but it doesn't work.

  2. #2
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    well if it is a letter
    a char should suffice
    instead of using the break
    use a bool flag.

    so
    while (seconds >0 && !done)
    if(letter=='w')
    done = true
    You ended that sentence with a preposition...Bastard!

  3. #3
    Registered User muffinman8641's Avatar
    Join Date
    Feb 2011
    Location
    Eastern-Central PA
    Posts
    76
    Thanks Eman, but your code lacks syntax in several ways (curly braces, etc.).

  4. #4
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    ha ha it is pseudo code..don't expect me to write it properly
    You ended that sentence with a preposition...Bastard!

  5. #5
    Registered User muffinman8641's Avatar
    Join Date
    Feb 2011
    Location
    Eastern-Central PA
    Posts
    76
    OK, I appreciate the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with do-while loop!!
    By robski in forum C++ Programming
    Replies: 6
    Last Post: 04-04-2010, 02:29 AM
  2. Flag-Controlled Loops
    By CPPN0OB in forum C++ Programming
    Replies: 10
    Last Post: 03-22-2010, 11:35 AM
  3. Breaking out of the loop
    By ICool in forum C Programming
    Replies: 5
    Last Post: 09-24-2007, 09:27 AM
  4. while (cin) loop problems
    By SeXy_Red in forum C++ Programming
    Replies: 5
    Last Post: 11-06-2005, 04:04 PM
  5. Two cins in a loop
    By chrismax2 in forum C++ Programming
    Replies: 4
    Last Post: 03-12-2004, 02:08 AM

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