programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# using for loops in calculations

Greenhorn
Posts: 10
• Number of slices to send:
Optional 'thank-you' note:
My problem is the fact that i cannot get the loop to properly run correctly to calculate the second half table which is displayed with Months on the left and CD Value on the right. I just need to be pointed in the right direction, i have spent a lot of time trying to figure this out. thanks for taking the time to look at my code.

Ranch Hand
Posts: 492
• Number of slices to send:
Optional 'thank-you' note:
are you sure all of the formulas for percent yield, monthly yield are correct?

Andrew Albers
Greenhorn
Posts: 10
• Number of slices to send:
Optional 'thank-you' note:
the ones before the loop i know are correct, once i figure out how to properly loop the math part ill know if my the equation in the loop is correct. i believe it is though.

Hunter McMillen
Ranch Hand
Posts: 492
• Number of slices to send:
Optional 'thank-you' note:
So I think I see what you're trying to do here, for the loop part you want to print out the number of months from 1 to (whatever the user enters) right? Then you want to calculate how much money is gained on the cd per month and display it across from the month. is this right??

Andrew Albers
Greenhorn
Posts: 10
• Number of slices to send:
Optional 'thank-you' note:
yup, then its prints out like:
Months
1
2
3
etc

CD Value
original + 1 month of interest
and so on

except months is across from CD Value.

Hunter McMillen
Ranch Hand
Posts: 492
• Number of slices to send:
Optional 'thank-you' note:
Ok, I know what you're doing wrong, you have a few problems here.
First this formula:

is wrong.

if my deposit is 500 and my annual % yield is 2% then this returns 500.83333333, this is the total i accumulated not the amount yield per month.
the correct formula is:

Second, you don't need to redefine monthlyYield as monthlyYield1, because it doesnt change from month to month, its constant.

Third, you dont need two for loops, you only need one.
declare a new variable to hold to total cd value;
example:

hope this helps
Hunter.

Andrew Albers
Greenhorn
Posts: 10
• Number of slices to send:
Optional 'thank-you' note:
thanks alot for the help it is very much appreciated. i gotta say this site is much more beginner friendlier than others.

Bartender
Posts: 5465
212
• Number of slices to send:
Optional 'thank-you' note:
Note however that the code above is correct, provided you don't need to work with compound interest, which is very unusual (especially when the number of months is more than 12).

Greetings,
Piet

 Don't get me started about those stupid light bulbs.