
-----------------------------------
Infinit1
Mon Oct 31, 2011 4:47 pm

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)





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

-----------------------------------
Tony
Mon Oct 31, 2011 5:21 pm

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 - [tdoc]return[/tdoc] would probably get you there faster. You might or might not been to be inside a procedure for this to work.

3 - [tdoc]quit[/tdoc] throws an exception that will drop like a rock through your code and cause it to end.

-----------------------------------
Infinit1
Mon Oct 31, 2011 5:45 pm

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

-----------------------------------
Infinit1
Tue Nov 01, 2011 4:34 pm

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

-----------------------------------
Beastinonyou
Tue Nov 01, 2011 4:41 pm

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: 

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)

-----------------------------------
Infinit1
Tue Nov 01, 2011 6:21 pm

RE:How do i get my program to quit when the number is less or more ~!!~~!! :(
-----------------------------------
Sorry, but I dont get it :( i tried putting in 

for i : 01..yrs
    put i: 01
end for

and other numbers after "put i: " , but its always wrong.

-----------------------------------
Tony
Tue Nov 01, 2011 6:27 pm

Re: RE:How do i get my program to quit when the number is less or more ~!!~~!! :(
-----------------------------------
i tried ... other numbers after "put i: " , but its always wrong.
Have you tried



-----------------------------------
Beastinonyou
Tue Nov 01, 2011 6:31 pm

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'


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:


for i : 1 .. 10
     if i > 0 and i < 10 then
         put "" : 9, "0", i 
    else
         put i : 11
    end if
end for


-----------------------------------
Aange10
Tue Nov 01, 2011 6:32 pm

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
[/code] 

is saying either. I think it means 10 spaces, from playing with it.

-----------------------------------
Infinit1
Tue Nov 01, 2011 6:33 pm

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

-----------------------------------
Beastinonyou
Tue Nov 01, 2011 6:56 pm

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 

 " ",


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.


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


-----------------------------------
Infinit1
Tue Nov 01, 2011 7:10 pm

RE:How do i get my program to quit when the number is less or more ~!!~~!! :(
-----------------------------------
lol, I wish i could use that :( 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 :)

The walking dead = 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

-----------------------------------
Beastinonyou
Fri Nov 11, 2011 7:50 am

Re: RE:How do i get my program to quit when the number is less or more ~!!~~!! :(
-----------------------------------
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:

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:

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.

