Thread: Is this possible?

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    14

    Is this possible?

    I have made improvements to my number game. I have made it so you have to enter a number that you will guess. Like this:

    You enter 651. That would be the number you have to guess.

    But, when you enter the 651, it stays viewable. I want it to make it so the number doesn't show up. Here's what happens:

    Enter the number you will be trying to guess: 651

    Is it possible to make the 651 appear as something else after you push enter? Here's the script for my program:

    Code:
    //Number game
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    {
            //game description
            cout<< "I took this out because of a scroll bar. It was just rules for the game.";
    
            //entering the correct number
            int correct;
            cout<<"Enter the number that you will be trying to guess:";
            cin>>correct;
    
    	//entering loopcounts
    	int loopCount;
            loopCount=15;
    	
    	//entering a guess
    	int guess;
    	while(loopCount>0)
    	{
    		//enter the guess
                    loopCount=loopCount--;
    		cout<<"Enter a guess:\n";
    		cin>>guess;
    		
    		if(guess==correct)
    		{
    			//correct
    			cout<<"That is correct! Press any key to exit.\n";
                            getch();
    			break;
    		}
    		else
    		if(guess>correct)
    		{
    			//lower message
    			cout<<"That is incorrect. The number is lower. Only "<<loopCount<<" guesses remaining.\n";
    		}
    		else
    		{
    			//higher message
    			cout<<"That is incorrect. The number is higher. Only "<<loopCount<<" guesses remaining.\n";
    		}
    	}
     	return 0;
    }
    Last edited by DarkSFK; 08-04-2002 at 01:42 PM.

  2. #2
    Unregistered
    Guest
    if you have the non'standard C++ file, conio.h, it has a getch() function that receives keyboard input, places it into the desired variable and doesn't print it to the screen. That might help you.

  3. #3
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Doesn't getch( ) take the first key stroke? So to get the 3 digit guess number you will have to use it 3 times and convert them to a single number. Random numbers are easier
    Couldn't think of anything interesting, cool or funny - sorry.

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    14
    I don't know how to do random numbers yet.

    EDIT: Hmmm............ does anyone know how to set the variable as a random number between 1 and 1000 everytime you open the file?
    Last edited by DarkSFK; 08-04-2002 at 07:56 PM.

  5. #5
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Search the board for random numbers. I think it is even in the FAQ.

Popular pages Recent additions subscribe to a feed