-
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;
}
-
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.
-
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 :)
-
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?
-
Search the board for random numbers. I think it is even in the FAQ.