Posted: Wed Mar 26, 2008 4:17 pm Post subject: program 'end loop's before I tell it to
This program is a learning project for me which uses some commands I have figured out for myself which weren't taught in my class yet (gr. 10 computer programming)
All problems are explained in the code , beginning in 'ERROR'
code:
% variable declarations
var age : int
var timeleft : int
var seeage : string
var total : int
var gender : string
%introduction to program
loop
put "This program will show you (inaccuratly)"
put "How long you have left to live."
% optional start
put "would you like to know? (yes or no)"
get seeage
exit when seeage = "no"
%input (age)
put "Enter your age by typing on the keyboard."
get age
%calculations
total := 81 - age
% a message to the user based on age
%ERROR only some work.
put "you have ", total, " years left to live"
if total < 0 then
put "your dead!"
elsif total > 0 and total < 20 then
put "you haven't got much time left!"
elsif total > 20 and total < 30 then
put "getting on in years"
elsif total > 30 and total < 40 then
put "midlife crisis, anyone?"
elsif total > 40 and total < 50 then
put "Time to settle down"
elsif total > 50 and total < 60 then
put "your rebellious years are over. get used to it."
elsif total > 60 and total < 0 then
put "why do you care? you've got lots of time left!"
elsif total = 0 then
put "TIme to organize a funeral!"
%restart the program.
% ERROR Doesn't seem to work, always reverts to the beginning
put "Would you like to do it again, "
put "so that you can lie about your age "
put "and get a better score? "
put "(yes or no)"
get seeage
exit when seeage = "no"
end if
end loop
Sponsor Sponsor
Mackie
Posted: Wed Mar 26, 2008 4:23 pm Post subject: RE:program \'end loop\'s before I tell it to
Ok, all you really need to do is move the 'end if' from after the:
code:
exit when seeage = "no
to before the comment '%restart the program.'
In it's current state you only get the decision if you were 81.
Insectoid
Posted: Wed Mar 26, 2008 4:56 pm Post subject: Re: program 'end loop's before I tell it to
Ah! Thank you! That solved everything! We actually haven't done looping yet in class, it was something I figured out for myself, so I don't know everything yet. I don't even know what 'end if' does, it's only there because turing told me to put it there.
My teacher's a dink, actually, he's spent 3 days teaching us what names you can't give to a variable/constant/etc.
Thank's for a quick reply!
Sean
Posted: Wed Mar 26, 2008 4:59 pm Post subject: Re: program 'end loop's before I tell it to
The end if is to end the if statement that you were using.
And any loop questions, or any other general ones, all of us are here to help.
Insectoid
Posted: Wed Mar 26, 2008 5:12 pm Post subject: RE:program \'end loop\'s before I tell it to
Just adjusted it a bit, to show what I learn on my own!
added some loops so that it only shows the first 'would you like to play' bit once, then skips every subsequent loop. 10 minutes ago, I had no clue how to do this!
code:
% variable declarations
var age : int
var timeleft : int
var seeage : string
var total : int
var gender : string
%introduction to program
loop
loop
put "This program will show you (inaccuratly)"
put "How long you have left to live."
% optional start
put "would you like to know? (yes or no)"
get seeage
cls
exit when seeage = "yes"
end loop
%input (age)
loop
put "Enter your age by typing on the keyboard."
get age
%calculations
total := 81 - age
% a message to the user based on age
%ERROR only some work.
put "you have ", total, " years left to live"
if total < 0 then
put "your dead!"
elsif total > 0 and total < 20 then
put "you haven't got much time left!"
elsif total > 20 and total < 30 then
put "getting on in years"
elsif total > 30 and total < 40 then
put "midlife crisis, anyone?"
elsif total > 40 and total < 50 then
put "Time to settle down"
elsif total > 50 and total < 60 then
put "your rebellious years are over. get used to it."
elsif total > 60 and total < 0 then
put "why do you care? you've got lots of time left!"
elsif total = 0 then
put "TIme to organize a funeral!"
end if
%restart the program.
% ERROR Doesn't seem to work, always reverts to the beginning
put "Would you like to do it again, "
put "so that you can lie about your age "
put "and get a better score? "
put "(yes or no)"
get seeage
exit when seeage = "no"
end loop
end loop
also, the F2 tabbing thing I found out on my own too, after seeing my teacher do it (but I didn't see what button(s) he pressed)
Sean
Posted: Wed Mar 26, 2008 5:18 pm Post subject: Re: program 'end loop's before I tell it to
You don't need the extra loops.
It was fine the way you had it before.
Turing:
%variable declarations var age :int var timeleft :int var seeage :string var total :int var gender :string %introduction to program loop
put"This program will show you (inaccuratly)" put"How long you have left to live."
% optional start put"would you like to know? (yes or no)" get seeage
exitwhen seeage ="no"
%input (age)
put"Enter your age by typing on the keyboard." get age
%calculations
total :=81 - age
% a message to the user based on age %ERROR only some work. put"you have ", total, " years left to live" if total < 0then put"your dead!" elsif total > 0and total < 20then put"you haven't got much time left!" elsif total > 20and total < 30then put"getting on in years" elsif total > 30and total < 40then put"midlife crisis, anyone?" elsif total > 40and total < 50then put"Time to settle down" elsif total > 50and total < 60then put"your rebellious years are over. get used to it." elsif total > 60and total < 0then put"why do you care? you've got lots of time left!" elsif total =0then put"Time to organize a funeral!" endif
%Restarts program put"Would you like to do it again, " put"so that you can lie about your age " put"and get a better score? " put"(yes or no)" get seeage
exitwhen seeage ="no" endif
endloop
Insectoid
Posted: Wed Mar 26, 2008 5:24 pm Post subject: RE:program \'end loop\'s before I tell it to
But that way, after you type 'yes' in the 'restarts program' section (or any other word that isn't 'no') you then had to type it in again in the 'introduction to program' section.
ex. 'would you like to play again?'
type: yes
then : 'would you like to play?'
its like playing a game that goes through all the opening credits when you go to the menu *couph*bowman 2*couph*
Sean
Posted: Wed Mar 26, 2008 5:27 pm Post subject: Re: program 'end loop's before I tell it to
Do it your way then, I was just removing the extra loops because I felt they weren't needed. If someone accidently continued your program when they wanted to exit, it then allows them to have the second opportunity.
Sponsor Sponsor
Insectoid
Posted: Wed Mar 26, 2008 5:37 pm Post subject: RE:program \'end loop\'s before I tell it to
I se your reasoning, but that is what the little X in the corner of the dialog box is for.
This is starting to sound a bit...heated. Don't know why, but it is.
Sean
Posted: Wed Mar 26, 2008 5:43 pm Post subject: Re: program 'end loop's before I tell it to
Naw, it wasn't getting heated. If I made it look like it then I am sorry.
It's up to you on the way you want to do it.
Also, I suggest adding some cls 's into your program to clear away any unnecessary data that is showing after you reset.
Insectoid
Posted: Wed Mar 26, 2008 5:47 pm Post subject: RE:program \'end loop\'s before I tell it to
Darn you, you posted while I was editing the thing!
anyway, I wasn't bothered, it looked to me like you were getting a bit defensive, maybe thought I was being..you know what, never mind.
Anyway, I was going to say (until you rudefully replied to my post while I was editing it) that this is my 'learning program' that will see many frequent updates as I learn more about turing, like now I am about to change the background color, which I just learned how to do.
Sean
Posted: Wed Mar 26, 2008 5:48 pm Post subject: Re: program 'end loop's before I tell it to
Use a cls after the colourback so it does the entire screen, not the given text areas that are present on your output.
Insectoid
Posted: Wed Mar 26, 2008 5:55 pm Post subject: RE:program \'end loop\'s before I tell it to
Ha! you solved my problem before it even came up! I just going to ask how to fix it!
seems it doesn't work if you use drawfillbox as I saw somebody do. Now I just have to wait for my teacher to tell me why you do it that way, because then I can figure more things out!
Sean
Posted: Wed Mar 26, 2008 5:57 pm Post subject: Re: program 'end loop's before I tell it to
You can use Draw.FillBox but you have to do it before everything. It works in layers, your put statements would go first, if you had the box, then the box would be over top of what was before it. Doing it before, layers it at the bottom.
Mackie
Posted: Wed Mar 26, 2008 5:57 pm Post subject: RE:program \'end loop\'s before I tell it to
The screen is only updated around where the text is . When you clear the screen it is wiped and the full color is shown.