I get an error that my variables are not initializing but I thought I set the program up to accept user input for the calculation. The warnings I get are on the principal, rate, and term. the only other thing I can think of is the program needs some starting point for the variables like principal = 200000, rate = .0575, and term = 30 But I was under the impression that would set the variables to those values. I tried to put those values in but now I just get a black box when it runs that does not take user input, although there are no errors.
int main()
{
//declare variables
double mrate, payment, principal ,rate;
int totalpayments, term;
mrate = rate/12; //monthly interest rate
totalpayments = term * 12; //amount of total payments
char indicator = 'y';
while( indicator == 'y' || indicator == 'Y')
//mortgage formula
payment = (principal * pow(mrate + 1, totalpayments) * mrate)/(pow(mrate + 1,totalpayments ) - 1);
while( indicator == 'y' || indicator == 'Y')
{
//get user input
cout << endl
<< "Enter principal amount in 100000 format: ";
cin >> principal;
cout << endl
<< "Enter the interest rate of the loan in .0575 format: ";
cin >> rate;
cout << endl
<< "Enter the term on the loan in a 30 format: ";
cin >> term;
cout << endl
<< "Your monthly payment is " << payment << " dollars a month."
<<endl;
cout << "Do you wish to calculate another loan(y or n)? ";
cin >> indicator;
return 0;
}
int main()
{
//declare variables
double mrate, payment, principal ,rate;
int totalpayments, term;
mrate = rate/12; //monthly interest rate
totalpayments = term * 12; //amount of total payments
char indicator = 'y';
while( indicator == 'y' || indicator == 'Y')
//mortgage formula
payment = (principal * pow(mrate + 1, totalpayments) * mrate)/(pow(mrate + 1,totalpayments ) - 1);
while( indicator == 'y' || indicator == 'Y')
{
//get user input
cout << endl
<< "Enter principal amount in 100000 format: ";
cin >> principal;
cout << endl
<< "Enter the interest rate of the loan in .0575 format: ";
cin >> rate;
cout << endl
<< "Enter the term on the loan in a 30 format: ";
cin >> term;
cout << endl
<< "Your monthly payment is " << payment << " dollars a month."
<<endl;
cout << "Do you wish to calculate another loan(y or n)? ";
cin >> indicator;
return 0;
}
Comment