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

Username:   Password: 
 RegisterRegister   
 Using counter to go by a calculation(help)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
tooring




PostPosted: Thu Jan 04, 2007 4:28 pm   Post subject: Using counter to go by a calculation(help)

I have this assignment and need some help.

I have to make an interest program and this is what I have so far. The program should tell the user the investment and interest by what ever compounding period the user chooses.

Im having trouble at this, because when I enter 10,12,Q, and 12 I only get 10.30 which is the the investment on the 3rd months. It dosent show that for the first 2 months it should be 10.00.

Any help would be good


code:
var taxinvestment, interestrate, compoundperiod, annual : real
var ti, ir, cp, toi: string
var termofinvestment: int
var a1,a2,a3,a4,a5,a6:real
var a8:int
put "This program will calculate and print a table showing how your cash investment"
put "accumulates over a period of time."

put "Please enter your tax investment"
loop
    get ti
    exit when strrealok (ti) = true
    put "Invalid input, please enter your tax investment."
end loop
taxinvestment := strreal (ti)

put "Please enter your interest rate"
loop
    get ir
    exit when strrealok (ir) = true
    put "Invalid input, please enter your interest rate."
end loop
interestrate := strreal (ir)

put "Please enter your compound period"
put "M=Monthly"
put "Q=Quarterly"
put "S=Semi-Anually"
put "A=Anually"
loop
    get cp
    exit when cp = "m" or cp = "M" or cp = "a" or cp = "A" or cp = "Q" or cp = "q" or cp = "s" or cp = "S"
    put "Invalid input, please enter your compound period (monthly, annually, quarterly, semi-annually)."
end loop
if
        cp = "m" or cp = "M" then
    compoundperiod := 12
elsif
        cp = "a" or cp = "A" then
    compoundperiod := 1
elsif
        cp = "S" or cp = "s" then
    compoundperiod := 2
elsif
        cp = "Q" or cp = "q" then
    compoundperiod := 4
else
    put "Nothing"
end if

put "Please enter your term of investment."
loop
    get toi
    exit when strrealok (toi) = true
    put "Invalid input, please enter your term of investment."
end loop
termofinvestment := strint(toi)


cls

locate (3,27)
a1:=interestrate/100
a2:=a1/compoundperiod
a3:=a2+1
a4:=a3*taxinvestment
put a4:0:2


for counter:1..termofinvestment by 3
put counter
end for
Sponsor
Sponsor
Sponsor
sponsor
Ultrahex




PostPosted: Thu Jan 04, 2007 11:34 pm   Post subject: (No subject)

Whoa... am I confused by your explanation...

ok

the problem is that it doesnt show each step of the investment ???

like you want

1st Term - 101.25
2st Term - 102.50
3nd Term - 103.75

in output???

or do you not understand the interest rate formulas...

which part are you confused about.
tooring




PostPosted: Fri Jan 05, 2007 8:36 am   Post subject: (No subject)

There should be 4 columns. One with the months, which is term in months(user enters)

The second with investment for each month (as it goes up)

The third with Interest added on each month(as it goes up)

The fourth with the total interest gained with investment added on

If you are still confused, I can upload the assignment sheet Razz
Ultrahex




PostPosted: Fri Jan 05, 2007 1:53 pm   Post subject: (No subject)

well for the columns your gonna need to use locate and a for loop like so....

code:

put "Column 1"
locate (1, 20)
put "Column 2"
locate (1, 40)
put "Column 3"


for i : 1 .. 5
    locate (i + 1, 1)
    put "1Row" ..
    put i
    locate (i + 1, 20)
    put "2Row" ..
    put i
    locate (i + 1, 40)
    put "3Row" ..
    put i
end for



just really need to change the output ... might also want to clear screen before writing that to the screen.

If your confused about the Math Part also and how to implement that ask for some help on that in this thread and ill get back to you.
tooring




PostPosted: Fri Jan 05, 2007 5:33 pm   Post subject: (No subject)

This is what I have right now. I have to make the investments go up every 3 months by the interest rate, but right now, its just saying 10 all the way. Help please, this is due Monday



code:
var annuall, investment, compoundperiod, interestrate : real
var tax, rate, compound, term : string
var termofinvestment, l2 : int

put "This program will calculate and print a table showing how your cash investment"
put "accumulates over a period of time."

put "Please enter your tax investment."
loop
    get tax
    exit when strrealok (tax) = true
    put "Invalid. Please enter your tax investment."
end loop
investment := strreal (tax)


    cls

    put "Please enter your interest rate."
    loop
        get rate
        exit when strrealok (rate) = true
        put "Invalid input, please enter your interest rate."
    end loop
    interestrate := strreal (rate)
   

    cls

    put "Please enter your compound period."
    put "M=Monthly"
    put "S=Semi-Annually"
    put "A=Anually"
    put "Q=Quarterly"
    loop
        get compound
        exit when compound = "m" or compound = "M" or compound = "a" or compound = "A" or compound = "q" or compound = "Q" or compound = "s" or compound = "S"
        put "Invalid. Please Enter the compound period letter."

        put "M=Monthly"
        put "S=Semi-Annually"
        put "A=Anually"
        put "Q=Quarterly"

        end loop
 
           cls
   
           if
            compound = "m" or compound = "M" then
        compoundperiod := 12
    elsif
            compound = "a" or compound = "A" then
        compoundperiod := 1
    elsif
            compound = "S" or compound = "S" then
        compoundperiod := 2
    elsif
            compound = "q" or compound = "Q" then
        compoundperiod := 4
    else
        put "Nothing"
    end if

    put "Please enter your term of investment in months."
    loop
        get term
        exit when strrealok (term) = true
        put "Invalid input, please enter your term of investment."
    end loop
    termofinvestment := strint (term)

    cls

    locate (3, 27)

    put "INTEREST ACCUMULATION TABLE"
    locate (5, 1)
    put "Initial Amount: $"
    locate (6, 1)
    put "Interest Rate:  %"
    locate (7, 1)
    put "Compunded:   M,Q,S,A"
    locate (8, 1)
    put "Term:        months"

    locate (5, 25)
    put investment
    locate (6, 25)
    put interestrate
    locate (7, 25)
    put compound
    locate (8, 25)
    put term


    locate (5, 50)
    put "M = Monthly"
    locate (6, 50)
    put "Q = Quarterly"
    locate (7, 50)
    put "S = Semi-annually"
    locate (8, 50)
    put "A = Annually"


    locate (10, 1)

    put "MONTH"
    l2 := 11

    for month : 1 .. termofinvestment
        l2 := l2 + 1
        locate (l2, 3)
        put month
    end for


    locate (10, 21)
    put "INVESTMENT"
    l2 := 11
    for investment1 : 1 .. termofinvestment
        l2 := l2 + 1
        locate (l2, 26)
        put investment
    end for
    l2 := 11

    locate (10, 41)
    put "INTEREST"
    for interest : 1 .. termofinvestment
        l2 := l2 + 1
        locate (l2, 44)
        put interest
    end for

    locate (10, 61)
    put "TOTAL"
    l2 := 11
    for count : 1 .. termofinvestment
        l2 := l2 + 1
        locate (l2, 63)
        put count
    end for

end if

    if interestrate > 1 then
    interestrate := interestrate / 100
tooring




PostPosted: Fri Jan 05, 2007 5:58 pm   Post subject: (No subject)

Here is the assignment I scanned if it helps you guys help me

http://img292.imageshack.us/img292/3323/projectys8.jpg
Ultrahex




PostPosted: Fri Jan 05, 2007 6:02 pm   Post subject: (No subject)

note you are not actually calculating the investment you are just saying it ... you need to calculate the investment at the point in time in your for loop, whether that is in advance and posting later.

like calculating the term its in and give the investment at that point in time.
tooring




PostPosted: Fri Jan 05, 2007 6:14 pm   Post subject: (No subject)

Ultrahex wrote:
note you are not actually calculating the investment you are just saying it ... you need to calculate the investment at the point in time in your for loop, whether that is in advance and posting later.

like calculating the term its in and give the investment at that point in time.


yeah. it has to show the investment at the different parts along the months. can you help me out
Sponsor
Sponsor
Sponsor
sponsor
blade360




PostPosted: Mon Jan 08, 2007 7:54 pm   Post subject: Re: Using counter to go by a calculation(help)

yes i agree with the people above me
Clayton




PostPosted: Mon Jan 08, 2007 10:11 pm   Post subject: Re: Using counter to go by a calculation(help)

tooring wrote:

yeah. it has to show the investment at the different parts along the months. can you help me out


aye, but the interest you gain adds on to the total you have already, so say you have a 5% interest rate every three months and you invest 100 dollars to start for 4 years (for 16 times to add the interest). Here is what a table would look like:

code:

Month | Amount in Bank | Interest
---------------------------------
1     |   $100         |   $0
2     |   $100         |   $0
3     |   $105         |   $5.00
4     |   $105         |   $0
5     |   $105         |   $0
6     |   $110.25      |   $5.25
7     |   $110.25      |   $0
8     |   $110.25      |   $0
9     |   $115.76      |   $5.51
...   |                |
12    |   $121.55      |   $5.79
15    |   $127.63      |   $6.08
18    |   $134.01      |   $6.38
21    |   $140.71      |   $6.70
24    |   $147.75      |   $7.04
27    |   $155.14      |   $7.39
30    |   $162.90      |   $7.76
33    |   $171.05      |   $8.15
36    |   $179.60      |   $8.55
39    |   $188.58      |   $8.98
42    |   $198.01      |   $9.43
45    |   $207.91      |   $9.90
48    |   $218.31      |   $10.40


hopefully that clears some things up for you. (Note that took me a long time to do Razz)
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  [ 10 Posts ]
Jump to:   


Style:  
Search: