----------------------------------- josh Fri Feb 13, 2004 9:01 pm Help with random number guess game ----------------------------------- I am trying to create this random number guess game and I need a little help. I want to make it so that once the user is asked to confirm if they are ready to begin (y/n) that either answer will start the game but will put a different "put" stamtent on the screen I am also having troubl writing the statment that ends the game (or if n e one can help with a loop restarts the game) if the user enters anything but an n or y var randmnumber, guess1, guess2, guess3 : int var name, yn : string %Making the random number randint (randmnumber, 1, 40) %introduction and getting name put "HELLO AND WELCOM TO THE RANDOM NUMBER GUESS GAME!!!!" put "I'm, your host Mr. Computer. Lets meet our contest!!!!" put "and your name is?" get name %Rules put "So today we have ", name, " with us. ", "Before we begin here, are the rules:" put "1. The number will be between 1 and 40" put "2. You will get three guesses" put "3. After each guess you will be given a hint to wether the number is higher or lower then your guess." put "Do you understnd these rules?" %Confirm ready to play put "Are you ready to play?" get yn if yn = "y" then put "good here we go" end if if yn = "n" then put "To bad we are going to start anyways" end if if yn not="n" or "y" then put "i am sorry the is not a valid answer please restart the game and answer with a y or n next time" end if ----------------------------------- Cervantes Fri Feb 13, 2004 9:22 pm ----------------------------------- shoulda read up on the syntax of if statements.. when you use 'or' / 'and' it doesn't keep the same beginning hence if yn not= "n" or "y" then is wrong. you need it to be like so if yn not= "n" or yn not= "y" then also it should be and not or. so here's your code with that problem fixed: var randmnumber, guess1, guess2, guess3 : int var name, yn : string %Making the random number randint (randmnumber, 1, 40) %introduction and getting name put "HELLO AND WELCOM TO THE RANDOM NUMBER GUESS GAME!!!!" put "I'm, your host Mr. Computer. Lets meet our contest!!!!" put "and your name is?" get name %Rules put "So today we have ", name, " with us. ", "Before we begin here, are the rules:" put "1. The number will be between 1 and 40" put "2. You will get three guesses" put "3. After each guess you will be given a hint to wether the number is higher or lower then your guess." put "Do you understnd these rules?" %Confirm ready to play put "Are you ready to play?" get yn if yn = "y" then put "good here we go" end if if yn = "n" then put "To bad we are going to start anyways" end if if yn not= "n" and yn not= "y" then put "i am sorry the is not a valid answer please restart the game and answer with a y or n next time" end if use a for statement for ending the game. read up on those and play around with it first, once you've tried your best only then come back here and ask for help :eh: ----------------------------------- josh Fri Feb 13, 2004 9:35 pm ----------------------------------- thanx for the help but I have read about 5 diffrent tutorials and I still can't figure out loops. I am not trying to sue this forum to cheat on a project becasue this isn't even for school. i am jsut trying to self teach myself turing. ----------------------------------- Cervantes Fri Feb 13, 2004 9:43 pm ----------------------------------- good job. self teaching is pretty hard :eh: I'll write you a loop tutorial tommorow morning. sorry :| I gotta get to bed early tonight :coffe: ----------------------------------- josh Fri Feb 13, 2004 9:44 pm ----------------------------------- thanx for all the help and I really apreciate the tutorial. ----------------------------------- Cervantes Sat Feb 14, 2004 11:24 am ----------------------------------- All done the tutorial :) http://www.compsci.ca/v2/viewtopic.php?p=33003#33003 hope it helps :) ----------------------------------- josh Sat Feb 14, 2004 12:20 pm ----------------------------------- thanks for the help this is a great tutorial. Really easy to understand