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

Username:   Password: 
 RegisterRegister   
 need help with my for sequence to correspond with my year for loop
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Velocity




PostPosted: Tue Nov 15, 2011 6:08 pm   Post subject: need help with my for sequence to correspond with my year for loop

What is it you are trying to achieve?

For the interest how do i make it so that interest will go up by 1 for each year
so for example if the interest is 10 in year 1 then the interest in year 2 will be 11, and in year 3 it will be 12... and so on
^^^^ I also need to put this in a for statement

What is the problem you are having?
adding a counter into a 1 .. interest for statement + 1
Describe what you have tried to solve this problem

made a for statement with a +1 in its loop for every year

Turing:


var sBalance, interest, fBalance : real
var get_statement : real
var years : string
colorback (91)
cls
put "How many years on your term? " ..
get years
put "What is your starting balance? " ..
get sBalance
put "What is your interest?(e.g. 9% = 0.09) " ..
get interest

Time.Delay (3000)
cls

fBalance := sBalance * interest
locate (5, 20)
put "Year"
locate (4, 33)
put "Starting"
locate (5, 33)
put "Balance"
locate (5, 48)
put "Interest"
locate (4, 65)
put "Final"
locate (5, 65)
put "Balance"

for i : 1 .. strint (years)
    put " "
    put "                   ", i
end for

% this is the section i need help in...
for j : interest
put j
end for



Please specify what version of Turing you are using
4.1.1a
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Tue Nov 15, 2011 6:24 pm   Post subject: RE:need help with my for sequence to correspond with my year for loop

First and foremost, there's no reason to make a new thread for this; generally when you're working with the same source code you did ten minutes ago, you ask your next question in the same thread.

Velocity wrote:


Describe what you have tried to solve this problem

made a for statement with a +1 in its loop for every year



And where did you do this? It's not in the source code you provided; ultimately, this would be the answer.



Example:

Turing:

var e : int := 10
for i : 1 .. 100
    e := e + 1 % Can be simplified to e += 1
    put "Current for: ", intstr(i)
    put "Current Counter: ", intstr(e)
end for
Velocity




PostPosted: Tue Nov 15, 2011 6:35 pm   Post subject: RE:need help with my for sequence to correspond with my year for loop

That's not what i was looking for.
Here, i'll just tell you the question that im working on and you tell me if im on the right track.

Write a program that inputs and amount of money (initial deposit), an interest rate and a number of years and then computes the bank blance at the end of each year for the number of years indicated. Output for each year (in a table) the number of the year, the balance at the beginning of the year, the interest earned for the year, and the blance at the end of the year. for example your table might look like this if the input was $100, 10%, 2 years :

Year Starting Balance Interest Final Balance
1 100 10 110
2 110 11 121
Aange10




PostPosted: Tue Nov 15, 2011 6:47 pm   Post subject: RE:need help with my for sequence to correspond with my year for loop

Hmm, I'll lay out a track for you. And if you need help filling in the blanks, you can ask here.

Turing:

% Define the variables
% Define the constants (i.e interest)
% Get the initial deposit
% Get the number of years to display
% Make a for from 1 .. years
% Each time the for FINISHES OUTPUTTING the balance, calculate the new balance
/* If the interest is a precent, do MoneyInBank + (MoneyInBank * interest)
   if the interest is a linear equation, just do MoneyInBank + Interest
*/







% Decorate however you'd like, go back and make it look good. Read the Turing
% Walkthrough and look for ways to make you're program more customizable :))
Velocity




PostPosted: Tue Nov 15, 2011 8:06 pm   Post subject: RE:need help with my for sequence to correspond with my year for loop

the part that i am stuck on for this whole time is the 6th step that you displayed. I dont know how to put that onto the screen using the for statement that i indicated with 1 .. years
Tony




PostPosted: Tue Nov 15, 2011 8:14 pm   Post subject: RE:need help with my for sequence to correspond with my year for loop

wouldn't it be the same for any other for-statement? How is "for i: 1 .. years" different from "for i: 1 .. 10" ?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Aange10




PostPosted: Tue Nov 15, 2011 8:22 pm   Post subject: Re: RE:need help with my for sequence to correspond with my year for loop

Velocity @ 15/11/2011, 7:06 pm wrote:
the part that i am stuck on for this whole time is the 6th step that you displayed. I dont know how to put that onto the screen using the for statement that i indicated with 1 .. years


And also in the step itself, I emphasized when to do it, and I took an extra long comment to tell you how.
Velocity




PostPosted: Tue Nov 15, 2011 9:47 pm   Post subject: RE:need help with my for sequence to correspond with my year for loop

@ Tony nope, because they have to input an amount and if they input it, then it cannot be 1 .. 10, 1 .. years is the get amount.

@ Aange i see what you did but i dont understand how to do the calculation for each year in one single for statement.
Sponsor
Sponsor
Sponsor
sponsor
Aange10




PostPosted: Tue Nov 15, 2011 10:23 pm   Post subject: Re: RE:need help with my for sequence to correspond with my year for loop

Velocity @ 15/11/2011, 8:47 pm wrote:
@ Tony nope, because they have to input an amount and if they input it, then it cannot be 1 .. 10, 1 .. years is the get amount.

@ Aange i see what you did but i dont understand how to do the calculation for each year in one single for statement.


Actually, tony is correct.

Tell me if you understand this

Turing:

var x : int := 5

put x + 5


What does that output? You must think I'm dumb right now to ask you what 5+5 is. But now realize what you did. You made x = 5

so when

Turing:

% Get the number of years to display


happens, it's storing the number into a variable, just like we stored 5 into x.

Turing:

var x : int := 5

put x + 5
% = 5 + 5 which is 10

for  i : 1 .. 5  % Repeats itself 5 times
end for

%Remember how x is := 5?

for i : 1 .. x % Repeats itself x times. At the moment, x = 5
end for


So, what would happen is x was a number you gave me? It'd no longer be constant, it'd be a variable. (Huh, what a familiar term...). Is it impossible for that variable to be 10? Nope.
Which means tony's thesis is correct.

However, lets advance to your problem;

Why don't we break down your question once again?

Velocity wrote:

how to do the calculation for each year in one single for statement


how to do the calculation

Turing:

Money := Money + Interest


for each year

Turing:

for i : 1 .. years
end for


in one single [for] statement

Turing:

for i : 1 .. years
    Money := Money + Interest
end for



Lets put our information together.

Turing:

var years, money, interest : int
get years
get money
for i : 0 .. years
    put "Year ",intstr(i), ":", money
    money := money + interest
end for
% Notice how in our for it followed the format I gave you.


Now let's follow Aange's advise, and pretty up the program.

[synt-- Well, actually, I think you can do that. (:
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 1  [ 9 Posts ]
Jump to:   


Style:  
Search: