Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Turing wont calculate the new total if added again+
Author Message
Stickman

Posted: Mon Mar 07, 2022 10:10 am   Post subject: Turing wont calculate the new total if added again+

Im having issue with the program and it keeps showing the same error every time and it not adding the new total

Expected result when:
Every time the command is run again by the loop it should add a new number to it.

the cause:
total := investment * intrate
the program keeps showing the same results.

i tried to fix it but it not working, this is for a assignment I have to hand in cause I need to catch up on the work.

Turing script:

%folder 0: note

%folder 1: var
var year: int
var value: real
var money: real
var investment: real
var total: real
var intrate: real
money := 0
intrate := 0
investment := 0
year := 0
%folder 2: script
get investment
get intrate
put "how much money do you want to have"
get money

loop
total := investment * intrate
year := year + 1

put "year:", year
put "total:", total
exit when total = money
end loop

scholarlytutor

Posted: Thu Mar 10, 2022 5:10 pm   Post subject: Re: Turing wont calculate the new total if added again+

Hi Stickman,

The code is mostly good, but there are a few of problems

The first problem is that your number stays the same each year. That's because your 'investment' variable never changes. Delete the total variable because you don't need it. Keep adding the value to 'investment' instead.

The second problem is with your maths. So let's say we invest \$200 at 5% interest. So after a year that is \$215. To get that, you need to multiply \$200 by 0.05:

investment += investment * (intrate/100)

Finally, to exit the loop, you exit when investment is >= money, not equal to, because most of the time the investment will not equal exactly the amount of money a person wants to have.

Here's the final code:

loop
investment += investment * (intrate / 100)
year := year + 1

put "year:", year
put "total:", investment : 0 : 2
exit when investment >= money
delay (1000)
end loop

The : 0 : 2 beside investment will round it to two decimal places so that it looks better. Also, the delay (1000) will wait 1 second so that you can see the results in slow motion.

Hope that helps!
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 2 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: