int main() { int number=rand()%100;
int guess=-1;
int trycount=0;
while(guess!=number && trycount<8) {
cout<<"Please enter a guess: ";
cin>>guess;
if(guess<number) cout<<"Too low"<<endl;
if(guess>number) cout<<"Too high"<<endl;
trycount++;
}
if(guess==number) cout<<"You guessed the number";
else cout<<"Sorry, the number was: "<<number;
return 0;
}
I see 3 problems with your post:
First, there was no code tags (can we get a sticky or something?)
Secondly, it was written in C++
and Thirdly, this trivial shit belongs in /pr/
>>7
god damn, I keep forgetting shit. Put this line before WEND: trycount% = trycount% + 1
Name:
Anonymous2009-09-05 1:15
SUPERIOR
module Main where
import IO
import Monad
import Random
maxTries :: Int
maxTries = 8
loop :: Int -> Int -> IO Bool
loop number try = do
if try < maxTries
then do putStr "Enter a guess: "
guess <- getLine >>= (return . read)
when (guess < number) (putStrLn "Too low.")
when (guess > number) (putStrLn "Too high.")
if guess == number
then return True
else loop number (try + 1)
else return False
main :: IO ()
main = do
hSetBuffering stdout NoBuffering
number <- randomRIO (1, 100)
won <- loop number 0
if won
then putStrLn "You win!"
else putStrLn "Sorry, please play again."