What should i do????????????

This is a discussion on What should i do???????????? within the C++ Programming forums, part of the General Programming Boards category; whats should i do should i loop this so it will repeat it self over and over again so its ...

  1. #1
    Registered User Joe100's Avatar
    Join Date
    Jul 2003
    Posts
    63

    What should i do????????????

    whats should i do should i loop this so it will repeat it self over and over again so its just not one line in the actual game
    Code:
    #include <iostream.h>
    #include <windows.h>
    #include <conio.h>
    int main()
    {
        int number;
        cout << "Guess The Number\n";
        cin >> number;
        if(number==rand()%100)
        {
            cout << "Correct\n";
            getch();
            return 0;
        }
        else
        {
            cout << "Incorrect\n";
            getch();
            return 0;
    
        }
        return 0;
    }
    "Be Quick Or Be Dead"

    [img]
    http://www.danasoft.com/sig/GU.jpg
    [/img]

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    10

  3. #3
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    First of all you should pick a valid title for this topic. A lot of people come here because they don't know what to do.

    And then, use
    Code:
    while(true)
    { 
      ...
    }
    around the input code (except for the first and last line in main(), leave them outside.
    You should give the user a chance to break out of the loop. So maybe use a second variable for the loop condition and set it to false based on user input.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Try...
    Code:
    #include <iostream>
    #include <windows.h>
    #include <conio.h>
    using namespace std;
    
    int main()
    {
        int number=0;
        while(1)
        {
            cout << "Guess The Number between 0-100 (press -1 to exit) \t";
            cin >> number;
            if ( number == -1)
            {
                    cout << "Bye..";
                    break;
            }
                    
            /* initialize random generator */
            srand ( time(NULL) );
            int compare = rand() % 100;
            
            if(number ==  compare)
            {
                cout << "Correct\n";
                getch();
            }
            else
            {
                cout << "Incorrect, the correct value was " << compare << '\n';
                getch();
            }
        }
        
        return 0;
    }

Popular pages Recent additions subscribe to a feed

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