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

Username:   Password: 
 RegisterRegister   
 How do i get my program to quit when the number is less or more ~!!~~!! :(
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Infinit1




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Infinit1




PostPosted: 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
Infinit1




PostPosted: 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
Beastinonyou




PostPosted: 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)
Infinit1




PostPosted: 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.
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Beastinonyou




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: 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.
Infinit1




PostPosted: 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
Beastinonyou




PostPosted: 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
Infinit1




PostPosted: 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?
Aange10




PostPosted: 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 (:
Beastinonyou




PostPosted: 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.
Infinit1




PostPosted: 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
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 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: