Computer Science Canada

Binary by ARP

Author:  a random person [ Fri Dec 23, 2005 11:55 am ]
Post subject:  Binary by ARP

this is a brand new guessing game that i came out with, there are 2 options on or off (1 or 0) there are 5 chances to begin with a number in the corect place is worth +1 a number out of place is worth -1 use that as a hint here is the 38 line code

code:

var wrong, UNum1, UNum2, UNum3, UNum4, CNum1, CNum2, CNum3, CNum4 : int
wrong:=5
randint (CNum1,0,1)
randint (CNum2,0,1)
randint (CNum3,0,1)
randint (CNum4,0,1)
loop
put "enter a four digit binary code one didget at a time"
cls
put "you have " ,wrong, " chances left"
get UNum1, UNum2, UNum3, UNum4
put UNum1, UNum2, UNum3, UNum4
if CNum1 not=UNum1 then
wrong := wrong-1
else
wrong:=wrong+1
end if
if CNum2 not= UNum2 then
wrong := wrong-1
else
wrong:=wrong+1
end if
if CNum3 not= UNum3 then
wrong := wrong-1
else
wrong := wrong+1
end if
if CNum4 not= UNum4 then
wrong := wrong-1
else
end if
exit when wrong < 1 or UNum1=CNum1 and UNum2=CNum2 and UNum3=CNum3 and UNum4=CNum4
end loop
if wrong < 1 then
put "you lose, the number was " ,CNum1,CNum2,CNum3,CNum4
else
put "you win"
end if


tell me ways for inprovement and they may be added. and please rate it

Author:  wtd [ Sat Dec 24, 2005 2:48 pm ]
Post subject: 

Proper formatting of your code would improve it. Smile

Author:  jrblast [ Sat Dec 24, 2005 9:38 pm ]
Post subject: 

make the get command get 1 variable, then split the variable in 4, it would look something like this (an example made on teh spot, not modifying your code) oh, and i wont bother declarig the variables


get fullNumber (1..4)

digit1 := fullNumber (1)
digit2 := fullNumber (2)
digit3 := fullNumber (3)
digit4 := fullNumber (4)

it hink thats it, if that doesnt work check the string manipulation tutorial, there should be something there


: