### assigning a value to variables

Im trying to calculate the balance at the end of the year given an annual investment, and a percentage rate of return. to do this im just putting the equation into a new variable labelled endYearBalance. when i try to use endYearBalance in the cout it gives me the wrong answer but when i take just the equation and stick it in, it gives me the right answer.... any help? the reason im trying to create a new variable for the equation is because this program should calculate and display the amount of years it will take to reach your ending investment goal...any help is appreciated

 ``1234567891011121314151617181920212223242526`` `````` void investmentInput(double& annualInvestment, double& returnRate, double& endGoal) { int year = 1; double endYearBalance; endYearBalance = (annualInvestment * (returnRate/100)) + annualInvestment; double newYear; newYear = endYearBalance + annualInvestment; cout << " Enter the amount you want to invest annually: "; cin >> annualInvestment; cout << " Enter the yearly percentage rate of return: "; cin >> returnRate; cout << " Enter investment goal: "; cin >> endGoal; cout << "Year" << " Balance (Jan. 1)" << " Balance (Dec. 31)" << endl; cout << year << " "<< annualInvestment << " " << endYearBalance << endl; // this gives me the wrong answer; // but when i input (annualInvestment * (returnRate/100)) + annualInvestment // on its own i get the right answer... }``````
Last edited on
You are calculating the endYearBalance on line 6 before you've even read the values the user input. So it's working with whatever data you pass, not what user inputs.
OMG OFCOURSE!! thank you!!!
Topic archived. No new replies allowed.