I need some help
Author |
Message |
blade360
|
Posted: Wed Jan 03, 2007 2:18 pm Post subject: I need some help |
|
|
I'm trying to write a program for this
But I can't seem to get it working properly
Here's what I have so far
code: | var randnum1, randnum2 : int
var input : string
var games : int
var rolls : int := 0
var tries : int := 0
loop
put "Enter the number of games to be played: " ..
get input
if strintok (input) then
games := strint (input)
exit
else
put "That's not a number, please try again"
end if
end loop
randint (randnum2, 1, 12)
for gamenum : 1 .. games
loop
randint (randnum1, 1, 12)
rolls := rolls + 1
delay (1000)
tries:= tries + 1
put "game", rolls
delay (1000)
put "Roll ", tries, ":", randnum1
if ((randnum1 = 7) and (rolls = 1)) then
delay (1000)
put "Iwin"
exit
elsif ((randnum1 = 11 and (rolls = 1))) then
delay (1000)
put "winner"
exit
elsif ((randnum1 = 2 or randnum1 = 12)) and (rolls = 1) then
delay (1000)
put "lose"
exit
elsif ((randnum1 = randnum1)) and ((rolls > 1)) then
delay (1000)
put " youwin"
exit
elsif ((randnum1 = 7) and (rolls > 1)) then
delay (1000)
put "you lose"
exit
end if
end loop
end for
|
I know some of it is pretty bad, but it made sense when I was writing it. Some parts work and some don't. Any help I receive will be greatly appreciated. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Wed Jan 03, 2007 4:11 pm Post subject: (No subject) |
|
|
Welcome to CompSci.ca!
First, I'd just like to point out that we don't do people's homework here. That's not what we're for. I realize that's probably not what you wanted, but the fact that you've posted your assignment sheet means the topic is in the air, so it needed to be said.
Second, it's good that you posted some code. To make it easier for us to help you, however, it'd be great if you could specify what part you're having trouble with. Talk a little bit about your code.
I'll point out one thing that's wrong with your code: you're using randint to get a random number between 1 and 12. That's not the same as rolling two six sided dice, because the probabilities are different. With 2 six sided dice, the chance of getting a 7 is higher than any other number, but with your randint method, the chance of getting a 7 is the same as any other number.
Oh, one more thing: please post descriptive topic titles. It helps keep things ordered, and actually helps you to get help. "Craps" would have sufficed. Thanks ![Smile Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
|
|