Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with random number guess game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
josh




PostPosted: Fri Feb 13, 2004 9:01 pm   Post subject: 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

code:
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

Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri Feb 13, 2004 9:22 pm   Post subject: (No subject)

shoulda read up on the syntax of if statements.. when you use 'or' / 'and' it doesn't keep the same beginning
hence
code:
if yn not= "n" or "y" then

is wrong. you need it to be like so
code:
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:

code:
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




PostPosted: Fri Feb 13, 2004 9:35 pm   Post subject: (No subject)

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




PostPosted: Fri Feb 13, 2004 9:43 pm   Post subject: (No subject)

good job. self teaching is pretty hard Eh

I'll write you a loop tutorial tommorow morning. sorry Neutral I gotta get to bed early tonight coffe
josh




PostPosted: Fri Feb 13, 2004 9:44 pm   Post subject: (No subject)

thanx for all the help and I really apreciate the tutorial.
Cervantes




PostPosted: Sat Feb 14, 2004 11:24 am   Post subject: (No subject)

All done the tutorial Smile

http://www.compsci.ca/v2/viewtopic.php?p=33003#33003

hope it helps Smile
josh




PostPosted: Sat Feb 14, 2004 12:20 pm   Post subject: (No subject)

thanks for the help this is a great tutorial. Really easy to understand
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: