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
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
asianrandy




PostPosted: Mon Oct 27, 2008 12:37 pm   Post subject: help with random number

i need to learn about random number, so i can ready for to making a guessing game for my assignment. please and thank you
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Mon Oct 27, 2008 1:46 pm   Post subject: RE:help with random number

Go into Turing and press F10. If that doesn't work, look through the Turing Walkthrough.
andrew.




PostPosted: Mon Oct 27, 2008 3:06 pm   Post subject: RE:help with random number

Like insectoid said, go into Turing and press F10. Search for randint and Rand.Int. Those should help you out.

Also, this should be in the Turing Help, not the Tutorials.
Tony




PostPosted: Mon Oct 27, 2008 3:09 pm   Post subject: RE:help with random number

moved to Turing Help.

Also -- it's Rand.Int(). (randint is deprecated)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
asianrandy




PostPosted: Tue Oct 28, 2008 12:07 pm   Post subject: Re: help with random number

am sorry
asianrandy




PostPosted: Tue Oct 28, 2008 12:27 pm   Post subject: RE:help with random number

code:
var number, guess : int
var count : int := 1
var my_money : real := 10.00
randint (number, 1, 10) %Picks a random number from 1 to 10
%Can make it pick from any set of numbers by changing the number '10' to any numver you want


put repeat (" ", 20), "Welcome to Randy's Guessing Game"
put "You are guessing three numbers between 1 and 10.Every guess cost you one dollar.Guess all three numbers before you run out of money and you. You start with $10."
put " You have $10 left in your account. One turn costs 1 dollar."
put "Can You Guess What It Is?"

loop %repeat code until stoped
    put "Enter Your Guess"

    get guess %user puts in his/her guess

    if guess = number then %If user guesses the correct number
        put "CORRECT"
        if count >= 1 then %number of tries are counted

            put "It took you ", count, " tries to get the number" %tells user how many tries it took them
        end if

        put "The number was ", number %puts what the secert number was
    end if

    if guess > number then %if the user inputs a number higher then the secrect number
        put "TO HIGH"
        var my_money : real := -1
    elsif guess < number then %if the user inputs a number lower then the secrect number
        put "TO LOW"
    end if

    count := count + 1 %each time the loop re-runs, count is added by one

    exit when guess = number %exit out of repeating loop when user gets the correct number

end loop %end the reapetative loop


i need help, the user the has $10 and if the user gets it wrong the user will lose 1, everytime the user get it wrong.
jbking




PostPosted: Tue Oct 28, 2008 12:32 pm   Post subject: RE:help with random number

Don't you need to declare a couple of variables outside the loop, e.g. $ of user and # of random numbers to be guessed?

Within the loop, it should be simple enough to keep track of what the user's money is by subtracting one if the guess is wrong.
asianrandy




PostPosted: Wed Oct 29, 2008 12:01 pm   Post subject: RE:help with random number

what the code for that
Sponsor
Sponsor
Sponsor
sponsor
jbking




PostPosted: Wed Oct 29, 2008 3:41 pm   Post subject: Re: help with random number

Here's your code with the few lines added for what I mean:

code:
var number, guess : int
var count : int := 0
var WhichRandomNumber : int := 1
var TotalRandomNumberCount : int :=3
var my_money : real := 10.00
randint (number, 1, 10) %Picks a random number from 1 to 10
%Can make it pick from any set of numbers by changing the number '10' to any numver you want


put repeat (" ", 20), "Welcome to Randy's Guessing Game"
put "You are guessing three numbers between 1 and 10.Every guess cost you one dollar.Guess all three numbers before you run out of money and you. You start with $10."
put " You have $10 left in your account. One turn costs 1 dollar."
put "Can You Guess What It Is?"

loop %repeat code until stoped
    put "Enter Your Guess"

    get guess %user puts in his/her guess
    my_money := my_money - 1
    count := count + 1

    % This gets changed to reflect the combinations possible.
    if guess = number then %If user guesses the correct number
        put "CORRECT"
        if count >= 1 then %number of tries are counted

            put "It took you ", count, " tries to get the number" %tells user how many tries it took them
        end if

        put "The number was ", number %puts what the secert number was
        WhichRandomNumber := WhichRandomNumber + 1
        if WhichRandomNumber = TotalRandomNumber
            put "Congratulations, you are a winner"
            exit
        else
             randint (number, 1, 10) %Picks a random number from 1 to 10
            count := 1
        end if
   elsif guess > number then %if the user inputs a number higher then the secrect number
        put "TOO HIGH"
    elsif guess < number then %if the user inputs a number lower then the secrect number
        put "TOO LOW"
    end if
    if (my_money=0.00)
       put "You are broke, sorry"
    end if

end loop %end the reapetative loop


So, the main changes are:
Decrement the money and increment the count as the user enters a number
Change the condition when the user gets a number right to see if the number of numbers is done or not.
Check at the end of the loop to see there is still money to play the game
asianrandy




PostPosted: Wed Oct 29, 2008 3:49 pm   Post subject: Re: help with random number

there was an error for the put "Congratulations, you are a winner" and put "You are broke, sorry".
isaiahk9




PostPosted: Wed Oct 29, 2008 6:51 pm   Post subject: RE:help with random number

you need a "Then" on the ifs above the two lines you pointed out.
asianrandy




PostPosted: Thu Oct 30, 2008 12:29 pm   Post subject: RE:help with random number

thanks
isaiahk9




PostPosted: Thu Oct 30, 2008 3:27 pm   Post subject: RE:help with random number

np
asianrandy




PostPosted: Fri Oct 31, 2008 1:04 pm   Post subject: RE:help with random number

i trying to figure out how to show how much money does user have on every question the user guess. i can't figure it out, l'm a noob at this ok.
jbking




PostPosted: Fri Oct 31, 2008 3:14 pm   Post subject: Re: help with random number

We were all noobs once, so here is the help on that:

Notice the line:
code:

         put "It took you ", count, " tries to get the number"


Which displays the number of times it took someone to get the right answer? Well that has what you need to do for the money part as it should be as simple as adding this line before the "Enter your guess" line:

code:

    put "You have $",money," remaining."


Or at least that would be my initial suggestion. While I haven't programmed in Turing I can pick up some basics and translate code from language to language at times pretty easily.
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 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: