Apr 11, 2008 at 5:07pm UTC
Any help in totaling my returns variable for output? Thanks
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double balance, interest_rate, returns, new_balance, years, return_total;
cout << "Enter interest rate\n\n";
cin >> interest_rate;
interest_rate /= 100;
cout << "Enter amt\n\n";
cin >> balance;
cout << "Enter years\n\n";
cin >> years;
for (int i =1; i<=years; i++){
returns = balance * interest_rate;
new_balance = returns + balance;
balance = new_balance;
cout << returns << endl;
}
cout << endl;
cout << new_balance;
cout << endl;
cout << endl << endl;
system ("PAUSE");
return 0;
}
Apr 11, 2008 at 7:36pm UTC
Right after "returns = balance * interest_rate;" just add "return_total += returns;"
Apr 11, 2008 at 8:47pm UTC
Thanks for the help but, I can not seem to get it to work. My cout << returns << endl; is printing out all my returns, each one depending on number of years I use but I just cannot get them to total up! driving me nuts, it's right there, just can't see it.
Apr 11, 2008 at 8:50pm UTC
Ahaaa! forgot to initialize return_total to 0 before loop. :) thanks!!