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

Username:   Password: 
 RegisterRegister   
 engineering Homework :(
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
zaczac




PostPosted: Sat Sep 27, 2008 6:52 pm   Post subject: engineering Homework :(

Well we just started learning about this program and we have to make a program. The program is a game of hangman and you must pick a number between 1-20 and if you get it wrong the program will draw another part of the body, Example if i guessed the number 5 and it was wrong then the program would draw a head, if i guessed wrong again it would draw the body, and so on. Heres what i got so far...

var num, rnum : int

loop
rnum := Rand.Int (1, 20)
put "Please Pick A Number between 1 and 20. 100 is to Exit."

loop

get num

if rnum = num then
put "You guessed it!"
exit
else
put "Wring. Guess Again."
end if

end loop

end loop


Im completely lost on how to get the program to draw the body if anyone could help id appreciate it a lot thanks in advanced Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Sep 27, 2008 7:42 pm   Post subject: RE:engineering Homework :(

You can use commands such as Draw.Oval() and Draw.Line() to draw graphics. Look up the documentation for their proper use.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
zaczac




PostPosted: Tue Sep 30, 2008 7:18 pm   Post subject: RE:engineering Homework :(

Heres what i got now

var numb, guess, counter : int
numb := Rand.Int (1, 20)
counter := 7-1
drawoval (100, 250, 50 ,50, black)
drawline (70, 40, 100, 100, black)
drawline (100, 100, 130, 40, black)
drawline (100, 100, 100, 200, black)
drawline (70, 140, 100, 180, black)
drawline (130, 140, 100, 180, black)
loop
put "Guess a number from 1 to 20."
get guess
if guess = numb then
put "Guess is right"
else
put "Guess is wrong"
end if
end loop


Still dont get how i could take parts away from my stick man if someone guesses somthing wrong >.< i tried using a counter but that didnt work =_- thanks for any suggestions.
Insectoid




PostPosted: Tue Sep 30, 2008 7:28 pm   Post subject: RE:engineering Homework :(

Use a counter to count how many times they got it wrong, and draw a part corresponding to that counter.

pseudo code:
[code]
if guess is wrong then
if counter = 1 then
draw head
elsif counter = 2 then
draw body
elsif....
end if
OneOffDriveByPoster




PostPosted: Tue Sep 30, 2008 7:33 pm   Post subject: Re: RE:engineering Homework :(

Erm... I think you want to add parts, not remove them...

A counter is a good approach. If the user makes his Xth wrong guess, then
draw the part Xth part.
S_Grimm




PostPosted: Wed Oct 01, 2008 7:50 am   Post subject: RE:engineering Homework :(

put a variable in the program, called something like numberwrong, and put it so "
if numberwrong = 1 then drawhead end if
if numberwrong = 2 then drawbody end if
Insectoid




PostPosted: Wed Oct 01, 2008 11:18 am   Post subject: RE:engineering Homework :(

Quote:

counter := 7-1


This is a problem. It says that your counter will always equal 6. You need to decrease it, and you need a loop. Replace 7 with 'counter'.

code:

counter := counter - 1


A nice programming thingummy that allows you to shorten this common piece of code:

code:

counter -= 1
Clayton




PostPosted: Wed Oct 01, 2008 8:38 pm   Post subject: Re: RE:engineering Homework :(

insectoid @ Wed Oct 01, 2008 11:18 am wrote:
Quote:

counter := 7-1


This is a problem. It says that your counter will always equal 6. You need to decrease it, and you need a loop. Replace 7 with 'counter'.

code:

counter := counter - 1


A nice programming thingummy that allows you to shorten this common piece of code:

code:

counter -= 1


I believe the term you are looking for here is syntactic sugar.
Sponsor
Sponsor
Sponsor
sponsor
S_Grimm




PostPosted: Thu Oct 02, 2008 7:56 am   Post subject: Re: engineering Homework :(

This is NOT a complete program, because i know that it will be deleted if it was, but i belive that it is what you wanted, no?

Turing:

var numb, guess : int
var numbwrong := 0
%Procedure Declarations
procedure getnumb
numb := Rand.Int (1, 20)
end getnumb

procedure drawbody %draws body
drawline (100, 100, 100, 200, red)
end drawbody

procedure drawleftarm %draws left arm
drawline (70, 140, 100, 180, black)
end drawleftarm

procedure drawhead %Draws head
drawoval (100, 250, 50 ,50, black)
end drawhead

procedure getguess
put "Input a guess between 1 and 20 : "..
get guess
end getguess

procedure checkforright
if guess = numb then
put "Your answer is right!"
getnumb
cls
elsif guess not= numb then
numbwrong += 1
end if
end checkforright
procedure DRAW
if numbwrong = 1 then
drawhead
end if
if numbwrong = 2 then
drawbody
end if
if numbwrong = 3 then
drawleftarm
end if
end DRAW

%Main Body of program
numb := Rand.Int (1, 20)  %gets the first number, has to be outside of loop
loop

DRAW
getguess
checkforright
View.Update
if numbwrong = 3 then
cls
put "GAME OVER!"
end if
exit when numbwrong = 3
end loop
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  [ 9 Posts ]
Jump to:   


Style:  
Search: