Author |
Message |
katastrophie
|
Posted: Thu Dec 06, 2007 5:48 pm Post subject: Generating random numbers from 1..12 |
|
|
I have this little project and it's about a dice game. Basically what you do is roll a dice and depending on the outcome you either lose, win or try again. It also prompts the user at the start of the game to enter the number of games they want to play and depending on what they input it will replay the game. At the end it'll determine the win average and display the number of games won and lost.
What I'm asking is how do you make it so that a random number is generated and displayed on the screen. I have already gotten the if statements down but I'm stumped on this part.
I'm using Turing version 6.55.
(Harnett's Hell 101) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
StealthArcher
|
Posted: Thu Dec 06, 2007 5:58 pm Post subject: Re: Generating random numbers from 1..12 |
|
|
katastrophie @ Thu Dec 06, 2007 4:48 pm wrote:
I'm using Turing version 6.55.
(Harnett's Hell 101)
Uhhh yeah sure, and my computer runs on an intel 40-core, at 3THz.
Anyway, what you are looking for is Rand.Int(1,12), assign it to a variable. |
|
|
|
|
|
Nick
|
Posted: Thu Dec 06, 2007 6:05 pm Post subject: RE:Generating random numbers from 1..12 |
|
|
wouldnt you want 2,12 since one die cant = 0 |
|
|
|
|
|
LaZ3R
|
Posted: Thu Dec 06, 2007 6:06 pm Post subject: Re: Generating random numbers from 1..12 |
|
|
Yep, Rand.Int (1,12) is what you are looking for.
Generates a random number between 1 and 12.
You might as well also take a look at the rand command as well in the help menu. Also useful |
|
|
|
|
|
katastrophie
|
Posted: Thu Dec 06, 2007 6:32 pm Post subject: Re: Generating random numbers from 1..12 |
|
|
I'm using Turing 6.55 because it was assigned to us in my Computer Science class. Yes I did use the randint commande but I want it to display the number and it doesn't. |
|
|
|
|
|
HeavenAgain
|
Posted: Thu Dec 06, 2007 6:54 pm Post subject: RE:Generating random numbers from 1..12 |
|
|
what?
or
code: | var randomNumber : int := Rand.Int(1,12)
put randomNumber |
doesnt work? |
|
|
|
|
|
Nick
|
Posted: Thu Dec 06, 2007 7:07 pm Post subject: RE:Generating random numbers from 1..12 |
|
|
the latest tuuring is 4.1.1 and its the last that will ever be |
|
|
|
|
|
Tony
|
Posted: Thu Dec 06, 2007 7:22 pm Post subject: RE:Generating random numbers from 1..12 |
|
|
heh, the thing is, DOS Turing went up at least to version 8.x. Some time after that WinOOT came out. Windows Object Oriented Turing, now commonly known simply as Turing is indeed up to v4.1.1 now. It's available for free
So 6.55 would be like... 6 major releases behind.
@momop - 4.1.1 is the last "Holtsoft" version of Turing. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
Nick
|
Posted: Thu Dec 06, 2007 7:30 pm Post subject: Re: RE:Generating random numbers from 1..12 |
|
|
Tony @ Thu Dec 06, 2007 7:22 pm wrote: 4.1.1 is the last "Holtsoft" version of Turing.
with any luck Holtsoft will open source it but this is in another thread so back on topic
Rand.Int should do you fine |
|
|
|
|
|
Dan
|
Posted: Thu Dec 06, 2007 8:14 pm Post subject: RE:Generating random numbers from 1..12 |
|
|
Auctly Rand.Int will not do him fine. The Dos version of turing was not oop and Rand.Int uses oop conspects in it's implmenation.
What he whonts is randint ( var i : int, low, high : int )
code: |
var i:int
randint ( i, 1, 6 )
put i
|
|
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
Nick
|
Posted: Thu Dec 06, 2007 8:16 pm Post subject: RE:Generating random numbers from 1..12 |
|
|
not oop????!!!!?!?!?!?!?!? how did you DOSers live back then o.O |
|
|
|
|
|
Zeppelin
|
Posted: Thu Dec 06, 2007 8:51 pm Post subject: Re: Generating random numbers from 1..12 |
|
|
Wat I want to know is how does a school still use DOS? |
|
|
|
|
|
katastrophie
|
Posted: Thu Dec 06, 2007 10:41 pm Post subject: Re: Generating random numbers from 1..12 |
|
|
Ok thanks for that. It works but now I have another problem. I'll show you a sample output:
Enter the number of games to be played.
3
Game 1
Roll 1: 11
You Win!
Game 2
Roll 1: 5
Roll 2: 8
Roll 3: 5
You Win!
Game 3
Roll 1: 9
Roll 2: 3
Roll 3: 4
Roll 4: 6
Roll 5: 7
You Lose!
=============
Summary of Games
Games won 2
Games Lost 1
Win Average 66%
=============
What I am having trouble with is that when you are entering the number of games to be played how do you get it to count the games and the rolls. I tried something like game + 1 but it doesn't seem to work. Sorry if I'm a bother, but this unit is troubling me. |
|
|
|
|
|
Zampano
|
Posted: Fri Dec 07, 2007 8:59 am Post subject: Re: Generating random numbers from 1..12 |
|
|
Well, I can't say confidently that your version of Turing supports this, but instead of using game + 1, use game:=game+1, or game+=1. Beyond getting that syntax working, you seem to know how to solve the problem.
And holy moly, Turing free?!
I can't believe this happened ten days ago as well.
This will certainly chage my computer science class. |
|
|
|
|
|
Nick
|
Posted: Fri Dec 07, 2007 9:01 am Post subject: RE:Generating random numbers from 1..12 |
|
|
try making the games varible into a for loop like so
code: |
get games
for i:1..games
put "game: ",i %i will equal how many times the loop has gone through yet
%game code will go here
end for
%summarry of games here
|
|
|
|
|
|
|
|