Hello, I am currently working on my first project which has us code a formula to predict the amount of money a person will save by investing in a retirement account. I have most of the equation working properly up until the last part. All of my variables are listed as doubles but in the last part I have to divide 2 values with decimals in them and it's not coming out right.
In the code I have FV2 = FV1/R; with the value of FV1 being 6660.54 and R being 0.0025. The result is supposed to read 2664216 but instead I keep getting 2.66422e+006. Anyone have an idea on what I'm doing wrong? If I need to post more of the code I will but I feel this is a simple mistake I am making that someone can easily point out.
Heres the code. Most of the values I rely on the user input but the teacher gave us an example of numbers to test it out. For annual salary enter 100000, paycheck frequency enter 2, percent sabed in retirement accounr enter 16, annual interest rate enter 6, how many more working years enter 40. With these values the equation at the bottom should lead to 2664216 for FV but I keep getting 2.66422e+006. I've already checked every value along the way and everything equals out until the last division.
int main() //start of main function
{
double salary; //Total salary
double frequency; //Number of paychecks per month
double A; //Annual savings before percent conversion
double annual_savings; //Annual savings in percent form
double B; //Annual interest rate before percent conversion
double annual_rate; //Annual interest rate in percent form
double working_years; //Years left until retirement
double annual_paychecks; //Total paychecks per year
double P;
float R;
double N;
float FV;
cout << "Please enter your annual salary:";
cin >> salary;
cout << "Please enter your paycheck frequency i.e. your number of paychecks recieved per month:";
cin >> frequency;
cout << "Please enter the percentage of your salary that you will save in your retirement account annually (including company contribution):";
cin >> A;
annual_savings = A/100;
cout << "Please enter your annual interest rate:";
cin >> B;
annual_rate = B/100;
cout << "How many more years do you intend on working before retirement? ";
cin >> working_years;
annual_paychecks = frequency * 12; //paycheck frequency * 12 months
P = (salary/annual_paychecks) * annual_savings;
R = annual_rate/annual_paychecks;
N = annual_paychecks * working_years;