How to erase when you type E, and plot when you type P
Author |
Message |
rcmp1234
|
Posted: Tue Mar 04, 2008 7:22 pm Post subject: How to erase when you type E, and plot when you type P |
|
|
Hi, I wrote a program to output a cat's face. I would like to know how to modify it so that when you type E, it erases the face and plots it again when you type the letter P
thanks! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
michaelp
|
Posted: Tue Mar 04, 2008 9:21 pm Post subject: RE:How to erase when you type E, and plot when you type P |
|
|
So, you erase the whole face, and then draw the face again when you press 'p'?
Just make a function for drawing the face. Then, for when the user presses 'p', you call "cls".
You can find out how to use input from the keyboard yourself. |
|
|
|
|
|
rcmp1234
|
Posted: Tue Mar 04, 2008 9:37 pm Post subject: Re: How to erase when you type E, and plot when you type P |
|
|
not sure what you mean and not sure how... |
|
|
|
|
|
syntax_error
|
Posted: Tue Mar 04, 2008 10:10 pm Post subject: RE:How to erase when you type E, and plot when you type P |
|
|
a) the turing walk through or b)just F10.... try it sometime. |
|
|
|
|
|
Tony
|
Posted: Tue Mar 04, 2008 10:54 pm Post subject: RE:How to erase when you type E, and plot when you type P |
|
|
there are a number of smaller problems involved
1. drawing a blank screen -- cls for clear
2. drawing a cat's face -- you've done that part
3. reading the keyboard one character at a time
Turing: |
var c: string(1)
loop
getch c
put "you pressed: ", c
end loop
|
functions (you might first encounter them as procedures, which is a special type of a function), as suggested, are a way to organize code into blocks. It makes things neater, easier to understand, and you very easily use the same code in multiple places. Probably not essential at this program though, since you shouldn't be repeating any code. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
BigBear
|
Posted: Wed Mar 05, 2008 9:04 am Post subject: Re: How to erase when you type E, and plot when you type P |
|
|
This will help you with the order of things.
Turing: |
var input : string (1) % (1) is needed when getching variable
%identifys the name of the procedure used to call it (run it) later
procedure drawcatface
%put your code to draw cat face here
end drawcatface
%Start of main program loop to continually ask for input
put "Press p to see a picture. Press c to erase the picture. Press x to quit."
loop
%Displays instructions
getch (input ) %gets input from the user in the way of one character
%Decide which key was entered and decides to draw cat face , clear the screen, or exit.
if input = "p" or input = "P" then
drawcatface %name of procedure just type its identifier to run the code in a procedure
elsif input = "c" or input = "C" then
cls %makes screen blank
put "Press p to see a picture. Press c to erase the picture. Press x to quit."
elsif input = "x" or input = "X" then
put "Thanks for playing. Hope you had fun." %puts this and program no longer accepts input from the user
end if
exit when input = "x" or input = "X" %will end program if x or X is entered
%if x or X wasn't entered it runs stays in loop
end loop
/*could also put
put "Thanks for playing. Hope you had fun."
here because it exits loop and run whatever is outside and it only exits when x or X is entered after is displays it nothing to run and program finishes*/
|
|
|
|
|
|
|
Tony
|
Posted: Wed Mar 05, 2008 10:39 am Post subject: RE:How to erase when you type E, and plot when you type P |
|
|
I think that was an unnecessary specific solution to the question. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
riveryu
|
Posted: Wed Mar 05, 2008 8:58 pm Post subject: RE:How to erase when you type E, and plot when you type P |
|
|
I thought he meant typing E or P as input not pressing E or P keys. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
syntax_error
|
Posted: Thu Mar 06, 2008 9:57 pm Post subject: RE:How to erase when you type E, and plot when you type P |
|
|
pressing makes more sense and does not disturb the image itself. |
|
|
|
|
|
|
|