Computer Science Canada

How do i get my program to quit when the number is less or more ~!!~~!! :(

Author:  Infinit1 [ Mon Oct 31, 2011 4:47 pm ]
Post subject:  How do i get my program to quit when the number is less or more ~!!~~!! :(

What is it you are trying to achieve?
To make an Investment calculator


What is the problem you are having?
I dont know how to get the program to quit and say " The number of years is more than 16 or less than 10, so we cannot calculate it" , and then quit


Describe what you have tried to solve this problem

if yrs >= 16 then
put " Cannot calculate unless the number of years are less than 16"

elsif yrs >=9 then
put " Cannot calculate unless the number of years are more than 9 "


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:



put " Investment calculator"

var b : real                                 
var it : real                                 
var yrs : int


put " Please enter the beginning balance "     
  get b                                         
 
put " Please enter the interest "               
  get it                                         
 
put " Please enter the amount of years "       
  get yrs
 
if yrs >= 16 then
        put " Cannot calculate unless the number of years are less than 16"
       
elsif yrs >=9 then
        put " Cannot calculate unless the number of years are more than 9 "


put "================================================="
put "Year", "      ", "Beginning", "    ", " Interest", "     ",      "Year End"
put "           ", "Balance", "       ", "Charged", "      ",   "Balance"             
put "================================================="
 

for i : 1 .. yrs
 
 
     put " ", i, "      ", b : 10 : 2, "   ", b * it : 10 : 2, "    ",      (b + (b * it)) : 10 : 2
 
b := b + (b * it)
     
   
end for

end if                   





Please specify what version of Turing you are using
4.1.1

Author:  Tony [ Mon Oct 31, 2011 5:21 pm ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

so you know when you want to quit, just not how. There are a number of methods.

1 - Get to the end of the program. You might have to think about program flow and how you nest your various control structures (if, loops, etc)

2 - return would probably get you there faster. You might or might not been to be inside a procedure for this to work.

3 - quit throws an exception that will drop like a rock through your code and cause it to end.

Author:  Infinit1 [ Mon Oct 31, 2011 5:45 pm ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

thx !! got it and learnt about return and quit :p

Author:  Infinit1 [ Tue Nov 01, 2011 4:34 pm ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

Can someone tell me how to get the "years" in the table to be aligned? Eg:
Years
01
02
03
04
..
10
etc

Author:  Beastinonyou [ Tue Nov 01, 2011 4:41 pm ]
Post subject:  Re: How do i get my program to quit when the number is less or more ~!!~~!! :(

You might want to look at this very simple example for spacing:

Turing:
for i : 1 .. 10
     put i : 10 % change '10' around to experiment
end for


Now, you just need to alter it to produce the results you wish. (have 0's in front of 1 digit numbers, etc)

Author:  Infinit1 [ Tue Nov 01, 2011 6:21 pm ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

Sorry, but I dont get it Sad i tried putting in

for i : 01..yrs
put i: 01
end for

and other numbers after "put i: " , but its always wrong.

Author:  Tony [ Tue Nov 01, 2011 6:27 pm ]
Post subject:  Re: RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

Infinit1 @ Tue Nov 01, 2011 6:21 pm wrote:
i tried ... other numbers after "put i: " , but its always wrong.

Have you tried
Beastinonyou @ Tue Nov 01, 2011 4:41 pm wrote:

code:
for i : 1 .. 10
     put i : 10 % change '10' around to experiment
end for

Author:  Beastinonyou [ Tue Nov 01, 2011 6:31 pm ]
Post subject:  Re: How do i get my program to quit when the number is less or more ~!!~~!! :(

I just tried to show you what happens when you put a number after the colon directly after putting 'i'

Turing:

for i : 1 .. 10
     put i : 10 % Simply puts Value of 'i' 10 spaces to the right
end for


now to modify it to have 0's in front of your numbers 1 to 10:

Turing:

for i : 1 .. 10
     if i > 0 and i < 10 then
         put "" : 9, "0", i
    else
         put i : 11
    end if
end for

Author:  Aange10 [ Tue Nov 01, 2011 6:32 pm ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

If it makes you feel better, I don't exactly understand what

code:

put i : 10


is saying either. I think it means 10 spaces, from playing with it.

Author:  Infinit1 [ Tue Nov 01, 2011 6:33 pm ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

nvm, thxi solved it though i did

put i: 01+yrs


Last question.., when it's asking for the "put statements" there is a space... how do i get rid of it?

Ex:

(space) What is the starting principal?
5000
(space) What is the interest rate?
0.07

Author:  Beastinonyou [ Tue Nov 01, 2011 6:56 pm ]
Post subject:  Re: How do i get my program to quit when the number is less or more ~!!~~!! :(

first, you should properly align a table, with clear column names. With the way you incorporate the pointless

Turing:
" ",


in between each section.. Heck, It'd be easier to put it all in one string.


Aside from that. How can this possibly form a table? You need to open the window up more to fit all the section, and use a for statement to make a grid.


Let me help you.

Turing:

var window : int := Window.Open ("graphics: 800; 600")

put repeat ("=", 90)
put "   Year     Beginning   Interest     Year        End       Balance    Charged    Balance"
put repeat ("=", 90)

var gridX : int := 0
var gridY : int := 400

for i : 0 .. 8
    drawline (gridX + (i * 90), gridY, gridX + (i * 90), gridY + 193, black)
end for

Author:  Infinit1 [ Tue Nov 01, 2011 7:10 pm ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

lol, I wish i could use that Sad but my teacher's gonna yell at me and tell me that I'm in grade 11 programming which is supposed to be "basic" and that I shouldn't use complex things that she hasn't taught us. It would make the other students feel like they don't know much..

Though thx for simplifying it for me, now i know how to make column and rows the proper way instead of putting"=" before the headings and "|" after every heading.

Finally finished my third program in turing Smile

The walking dead <3

how do i close this thread?

Author:  Aange10 [ Tue Nov 01, 2011 7:38 pm ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

You don't, this could help tons of other people who ask the same question (:

Author:  Beastinonyou [ Tue Nov 01, 2011 7:38 pm ]
Post subject:  Re: How do i get my program to quit when the number is less or more ~!!~~!! :(

You're teacher is restricting you of learning more advanced concepts, just because she doesn't want other students to be jealous?

Lmfao.. That's how you get 4+'s, you go Above And Beyond what the expectations are.


When I did my grade 11, I strived to add in details, and incorporate more advanced features and concepts, and that's how I've learned to use Turing a lot better than I did before. You have to explore and try other things on your own. Practice those concepts, and you get a better understanding of them.


At the pace your teacher is going, you won't get to array's til the end of your semester, and everyone will be smacking both themselves, and her on the head for not showing you how to use them earlier.


Hmm... by your Teacher's logic: If it hasn't been taught, you shouldn't be learning it, nor using it; We sure as heck wouldn't be this far with technology.

Side Note: The Walking Dead is absolutely amazing. Watch every episode numerous times. And I'm pretty sure only mods can close threads.

Author:  Infinit1 [ Tue Nov 01, 2011 8:06 pm ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

My teacher... she's new, she told us the first day just to do what she tell's you to, and don't complicate things by making it fancy and whatnot.

She doesn't mark our programs, she tells us to go to someone else's program and mark theirs, so it makes sense that i shouldn't do more than she tells me, or the "marker" of my program wont know how i did, what I did.

My teacher just marks the Programmer's guide and the User's guide

Side note: I like watching the walking dead, but when it showed the preview of the next episode, it showed Shane asking Lori "You told me to stay", then you see Lori *half undressed*... now i don't feel like watching it..

.. would be bad if someone from my class copied my program..facepalm

Author:  Dreadnought [ Tue Nov 01, 2011 11:30 pm ]
Post subject:  Re: How do i get my program to quit when the number is less or more ~!!~~!! :(

Man, that blows, I don't what I would've done if my teacher had done that.

I feel bad that you're being held back like this.
Maybe you can make a simple version for class, and a good one for yourself if you have the time.

Author:  tg851 [ Wed Nov 02, 2011 10:00 am ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

same issue here with the teacher,except its not him holding us back,its the administrative they send in to check were doing"board acceptable work",also look into error.halt to make it quit with a message

Author:  Velocity [ Thu Nov 10, 2011 10:49 pm ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

I had a project like this in grade 10, but it was more advanced but same topic. I got 100% << as always... if you want, you can pm me. I can send you mine and explain to you the terms and all that i used.

Author:  Velocity [ Thu Nov 10, 2011 10:53 pm ]
Post subject:  RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

to answer your question.
You can make an if statement and write :

if yrs >= 9 and yrs >= 16 then
quit

(or exit)
end if

or you can type

yrs1 := yrs >= 9 and yrs >= 16

if yrs1 then
exit
else
put ".... lalala ( or you dont have to do this and you can just end if)"
end if

Author:  Beastinonyou [ Fri Nov 11, 2011 7:50 am ]
Post subject:  Re: RE:How do i get my program to quit when the number is less or more ~!!~~!! :(

Velocity @ Thu Nov 10, 2011 10:53 pm wrote:
if yrs >= 9 and yrs >= 16 then
quit

(or exit)
end if

or you can type

yrs1 := yrs >= 9 and yrs >= 16

if yrs1 then
exit
else
put ".... lalala ( or you dont have to do this and you can just end if)"
end if


That is not even correct syntax, with making a variable to what an if statement could be. And when you put "if yrs1 then", that would work for a boolean. Not what you just did.
Plus, if yrs is >= 9 and >= 16, that's all numbers from 9 and up, beyond 16.

Quite simply, all you need is this:

Turing:
if years < 10 or years > 16 then
     put "Incorrect number of years. Must be between 10 and 16"
     delay (2000)
     exit
end if


or if you want the window to close, you'd need:

Turing:
var window : int := Window.Open ("graphics: 500; 500") % At the beginning of the program. Opens 500 by 500 window
Window.Close (window) % Can be used instead of exit, to fully close the window.


: