While Loops

This is a discussion on While Loops within the C++ Programming forums, part of the General Programming Boards category; for some reason, the while loop is preventing the player from playing the game. it compiles correctly. Code: #include <iostream.h> ...

  1. #1
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    While Loops

    for some reason, the while loop is preventing the player from playing the game. it compiles correctly.

    Code:
    #include <iostream.h>
    #include <string>
    int main()
    {
        float rnd;
        float guess;
        rnd = rand(20);
        cout << "Welcome to the number game!" << endl;
        cin.get();
        cout << "Enter a number between 1 and 20" << endl;
        int tries = 5;
        while(tries >= 1);
        {
        cin >> guess;
        if(guess < rnd)
        {
        cout << "Too low" << endl;
        tries -= 1;
        }
        if(guess > rnd)
        {
        cout << "Too high" << endl;
        tries -= 1;
        }
        if(guess == rnd)
        {
        cout << "You got it right!" << endl;
        }
        }
        return 0;
        }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>while (tries >= 1);
    What's that semi-colon for ?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    AAAHHHH!!!STUPID ME!!!!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiple thread for loops
    By lehe in forum C++ Programming
    Replies: 12
    Last Post: 03-29-2009, 01:01 PM
  2. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 01:18 AM
  3. recoursion or loops?
    By Mecnels in forum C++ Programming
    Replies: 2
    Last Post: 01-14-2002, 12:09 PM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM
  5. for loops - newbie q's
    By Narciss in forum C Programming
    Replies: 8
    Last Post: 09-26-2001, 03:44 AM

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