|
|
..
|
Class AverageThreeDiceGame
Import JJIO
Class AverageThreeDiceGame
--Name: YourLoginIdGoesHere
Routine starter(none) is public
Boxes change1, change2, change3 ofType bool
Box noChanges ofType bool
Box command ofClass Str
Boxes value1, value2, value3 ofType int
Box drawCount ofType int
Start
Set value1 = -1
Set value2 = -1
Set value3 = -1
Set drawCount = 0
Set change1 = true
Set change2 = true
Set change3 = true
Set noChanges = false --initial values
Repeat
If change1 then
Set value1 = RealToInt(Random()*6.0)+1
EndIf
If change2 then
Set value2 = RealToInt(Random()*6.0)+1
EndIf
If change3 then -- shows use of modulus ('%') operator
Set value3 = ((RealToInt(Random()*987654321.0))%6)+1
EndIf
Output "Your values are: "
Output value1
Output " "
Output value2
Output " "
Outputln value3
ExitOn noChanges or (drawCount==2)
Output "Do you want to exchange the first value ("
Output value1
Output ")?"
Output " 'y'es or 'n'o? ..."
Input command
Outputln command
If command.equals("y") or command.equals("Y") then
Set change1 = true
Else
Set change1 = false
EndIf
Output "Do you want to exchange the second value ("
Output value2
Output ")?"
Output " 'y'es or 'n'o? ..."
Input command
Outputln command
If command.equals("y") or command.equals("Y") then
Set change2 = true
Else
Set change2 = false
EndIf
Output "Do you want to exchange the third value ("
Output value3
Output ")?"
Output " 'y'es or 'n'o? ..."
Input command
Outputln command
If command.equals("y") or command.equals("Y") then
Set change3 = true
Else
Set change3 = false
EndIf
Set noChanges = not (change1 or change2 or change3)
Inc drawCount by 1
EndRepeat
--Did they win?
If ((IntToReal(value1)+IntToReal(value3))/2.0 == IntToReal(value2)) then
Outputln "Congratulations! The middle is the average of the first and last."
Else
Outputln "Sorry, the middle is not the average of the first and last."
EndIf
EndRoutine starter
EndClass AverageThreeDiceGame
|
|