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

Username:   Password: 
 RegisterRegister   
 Dice game help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sci23




PostPosted: Tue Nov 20, 2007 6:16 pm   Post subject: Dice game help

i need help on my program....when the total of the dice equals 12, the program doesn't output "you lose!", how do i make it output "you lose!" and is there any possible way that the program can find out which die was outputted instead of asking the user for the number rolled for both the dice?


code:

colour(blue)
put "Welcome to the game Dice"
colour(black)
procedure die1
drawbox(300,50,200,150,7)
drawfilloval(250,100,10,10,7)
end die1

procedure die2
drawbox(300,50,200,150,7)
drawfilloval(285,135,10,10,7)
drawfilloval(215,65,10,10,7)
end die2


procedure die3
drawbox(300,50,200,150,7)
drawfilloval(285,135,10,10,7)
drawfilloval(215,65,10,10,7)
drawfilloval(250,100,10,10,7)
end die3

procedure die4
drawbox(300,50,200,150,7)
drawfilloval(285,135,10,10,7)
drawfilloval(215,65,10,10,7)
drawfilloval(285,65,10,10,7)
drawfilloval(215,135,10,10,7)
end die4

procedure die5
drawbox(300,50,200,150,7)
drawfilloval(285,135,10,10,7)
drawfilloval(215,65,10,10,7)
drawfilloval(285,65,10,10,7)
drawfilloval(215,135,10,10,7)
drawfilloval(250,100,10,10,7)
end die5

procedure die6
drawbox(300,50,200,150,7)
drawfilloval(285,135,10,10,7)
drawfilloval(215,65,10,10,7)
drawfilloval(285,65,10,10,7)
drawfilloval(215,135,10,10,7)
drawfilloval(215,100,10,10,7)
drawfilloval(285,100,10,10,7)
end die6

procedure d1
drawbox(480,50,380,150,7)
drawfilloval(430,100,10,10,7)
end d1

procedure d2
drawbox(480,50,380,150,7)
drawfilloval(465,135,10,10,7)
drawfilloval(395,65,10,10,7)
end d2

procedure d3
drawbox(480,50,380,150,7)
drawfilloval(465,135,10,10,7)
drawfilloval(395,65,10,10,7)
drawfilloval(430,100,10,10,7)
end d3

procedure d4
drawbox(480,50,380,150,7)
drawfilloval(465,135,10,10,7)
drawfilloval(395,65,10,10,7)
drawfilloval(465,65,10,10,7)
drawfilloval(395,135,10,10,7)
end d4

procedure d5
drawbox(480,50,380,150,7)
drawfilloval(465,135,10,10,7)
drawfilloval(395,65,10,10,7)
drawfilloval(465,65,10,10,7)
drawfilloval(395,135,10,10,7)
drawfilloval(430,100,10,10,7)
end d5

procedure d6
drawbox(480,50,380,150,7)
drawfilloval(465,135,10,10,7)
drawfilloval(395,65,10,10,7)
drawfilloval(465,65,10,10,7)
drawfilloval(395,135,10,10,7)
drawfilloval(395,100,10,10,7)
drawfilloval(465,100,10,10,7)
end d6

var answer:string

put "Would you like to roll the dice?(y/n)"
get answer
if answer="y" then
var die : array 1 .. 6 of procedure dice

die (1) := die1
die (2) := die2
die (3) := die3
die (4) := die4
die (5) := die5
die (6) := die6

die (Rand.Int (1, 6))


var d : array 1..6 of procedure dice
d(1):= d1
d(2):= d2
d(3):= d3
d(4):= d4
d(5):= d5
d(6):= d6
d (Rand.Int (1, 6))

var diee,dce,di2,total,num1,num2:int

put"Enter the number of the first die you have rolled:"
get diee
case diee of
label 1 : put "You have rolled a 1"
label 2: put " You have rolled a 2"
label 3 :put "You have rolled a 3"
label 4 : put "You have rolled a 4"
label 5: put "You have rolled a 5"
label 6 :put "You have rolled a 6"
end case

put "Enter the number of the second die you rolled:"
get dce
case dce of
label 1 : put "You have rolled a 1"
label 2: put " You have rolled a 2"
label 3 :put "You have rolled a 3"
label 4 : put "You have rolled a 4"
label 5: put "You have rolled a 5"
label 6 :put "You have rolled a 6"
end case



if diee=1 then
num1:=1
elsif
diee=2 then
num1:=2
elsif
diee=3 then
num1:=3
elsif
diee=2 then
num1:=2
elsif
diee=3 then
num1:=3
elsif
diee=4 then
num1:=4
elsif
diee=5 then
num1:=5
elsif
diee=6 then
num1:=6
end if

if dce=1 then
num2:=1
elsif
dce=2 then
num2:=2
elsif
dce=3 then
num2:=3
elsif
dce=2 then
num2:=2
elsif
dce=3 then
num2:=3
elsif
dce=4 then
num2:=4
elsif
dce=5 then
num2:=5
elsif
dce=6 then
num2:=6
end if

total:=num1+num2
put "The total of the two dice equals:"
put total


if total= 7 then
put "You Win!"
elsif
total =11 then
put "You Win!"
elsif
total = 2 then
put "You Lose!"
elsif total =3 then
put "You Lose!"
if total =12 then
put "You Lose!"
else
put "you must match your point value"

end if
end if
end if
Sponsor
Sponsor
Sponsor
sponsor
Zeppelin




PostPosted: Tue Nov 20, 2007 6:28 pm   Post subject: Re: Dice game help

Replace everything after "put total" with this


if total = 7 then
put "You Win!"
elsif total = 11 then
put "You Win!"
elsif total = 2 then
put "You Lose!"
elsif total = 3 then
put "You Lose!"
if total = 12 then
put "You Lose!"
else
put "you must match your point value"

end if
end if
end if


Should work

PS. The game is called "Craps"
sci23




PostPosted: Tue Nov 20, 2007 6:34 pm   Post subject: Re: Dice game help

Zeppelin @ Tue Nov 20, 2007 6:28 pm wrote:
Replace everything after "put total" with this


if total = 7 then
put "You Win!"
elsif total = 11 then
put "You Win!"
elsif total = 2 then
put "You Lose!"
elsif total = 3 then
put "You Lose!"
if total = 12 then
put "You Lose!"
else
put "you must match your point value"

end if
end if
end if


Should work

PS. The game is called "Craps"


the 12 still doesn't work though
Zeppelin




PostPosted: Tue Nov 20, 2007 6:35 pm   Post subject: Re: Dice game help

Replace "if total = 12 then" with "elsif total = 12 then"
sci23




PostPosted: Tue Nov 20, 2007 6:39 pm   Post subject: Re: Dice game help

thanks for your help
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  [ 5 Posts ]
Jump to:   


Style:  
Search: