Hi doing a class exercise where I have to create a compound interest calculator in C++ using a for loop (no functions) I've worked through 99% of it and actually got it to work...... But it only runs through 1 iteration of the loop... The inter face is as follows:
Please Enter an Amount
(User enters an amount of type double)
Please Enter number of years
(User enters amount of years money was invested for)
Please Enter The Agreed rate of Interest
(User enters interest type double)
When ever I enter an amount in it only calculates the compound interest for 2 years,
First of all, your variables are non descriptive so without knowing what they represent it's difficult to follow.
CompUserInv <=NumYrs_Inv is this really what you want to compare against? you're saying continue to loop until CompUserInv <= NumYrs_Inv which I guess is the number of years invested? Then further down you have this:
Is CompUserInv a number of years invested or is it a $ amount? The code imples it's an amount to me considering it is added to the product of the quantity (NewUserInv * InterestRate_PA). Just need you to clarify.
Thanks, for the replies, what I'm trying to do is to have the user input an amount of years and for that to determine how many times it the calculation will loop, e.g
user enter 5 years
program will loop 5 times
and then printout the compounded interest
right now it only loops 2 times no matter how many years the user inputs.
I'll defiantly work on how I name my variables.....
@Browni3141 I posted the for loop I'm using for this exercise above.....
These are the variables I am using for this exercise
double UserInv_AmtIn = 0; // This variable is for the principle.
double NumYrs_Inv = 0; // This variable is for the number of years
double InterestRate_PA = 0; // This variable is for the interest rate
double NewUserInv = 0; // This variable is for the first years interest
double CompUserInv = 0; // This variable is for total after the compound interest
We where told in the exercise to use the calculation of: principle + (principle * interest rate)
and then repeat for as many times as the year, (no formulae), we told that using a for loop would make this easy...... I know I should have used simpler names for my variables I'm working on that
But I think I am may have put something the wrong way round in the for loop because when ever I enter a principle it gives me the correct total for only 2 years