I have the variables declared twice where i think they should be. If I declare them global I get an uninitialized error, the other position gives me a declaration error. Im using visual C++ express 08 on MS.
using namespace std;
using std::cout;
using std::cin;
using std::endl;
char indicator = 'y';
while( indicator == 'y' || indicator == 'Y')
//declare global variables
double mrate, payment, principal ,rate;
int totalpayments, term;
int main()
{
{
//get user input principal
cout << endl
<< "Enter principal amount in 100000 format: ";
cin >> principal;
// check principal data 1.0 to 999999999.9
if (principal <= 0.00 || principal > 999999999.9)
{
cout << "************** *************** *************** *************** *******" << endl;
cout << endl << "Principal - between 1 and 999999999.0" << endl;
cout << "************** *************** *************** *************** *******" << endl;
continue;
}
cout << endl
//get user input intrest rate
<< "Enter the interest rate of the loan in .0575 format: ";
cin >> rate;
if (rate <= 0.0000 || rate > .5999)
{
cout << "************** *************** *************** *************** *******" << endl;
cout << endl << "Interest Amount - between 1 and 31.99" << endl;
cout << "************** *************** *************** *************** *******" << endl;
continue;
}
cout << endl
<< "Enter the term on the loan in a 30 format: ";
cin >> term;
// check term input 1 -30
if (term <= 0 || term > 30)
{
cout << "************** *************** *************** *************** *******" << endl;
cout << endl << "Loan term years - between 1 and 30" << endl;
cout << "************** *************** *************** *************** *******" << endl;
continue;
}
}
//redclare variables
double mrate, payment, principal ,rate;
int totalpayments, term;
//mortgage formula
payment = (principal * pow(mrate + 1, totalpayments) * mrate)/(pow(mrate + 1,totalpayments ) - 1);
mrate = rate/12; //monthly interest rate
totalpayments = term * 12; //amount of total payments
// output
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;
}
using namespace std;
using std::cout;
using std::cin;
using std::endl;
char indicator = 'y';
while( indicator == 'y' || indicator == 'Y')
//declare global variables
double mrate, payment, principal ,rate;
int totalpayments, term;
int main()
{
{
//get user input principal
cout << endl
<< "Enter principal amount in 100000 format: ";
cin >> principal;
// check principal data 1.0 to 999999999.9
if (principal <= 0.00 || principal > 999999999.9)
{
cout << "************** *************** *************** *************** *******" << endl;
cout << endl << "Principal - between 1 and 999999999.0" << endl;
cout << "************** *************** *************** *************** *******" << endl;
continue;
}
cout << endl
//get user input intrest rate
<< "Enter the interest rate of the loan in .0575 format: ";
cin >> rate;
if (rate <= 0.0000 || rate > .5999)
{
cout << "************** *************** *************** *************** *******" << endl;
cout << endl << "Interest Amount - between 1 and 31.99" << endl;
cout << "************** *************** *************** *************** *******" << endl;
continue;
}
cout << endl
<< "Enter the term on the loan in a 30 format: ";
cin >> term;
// check term input 1 -30
if (term <= 0 || term > 30)
{
cout << "************** *************** *************** *************** *******" << endl;
cout << endl << "Loan term years - between 1 and 30" << endl;
cout << "************** *************** *************** *************** *******" << endl;
continue;
}
}
//redclare variables
double mrate, payment, principal ,rate;
int totalpayments, term;
//mortgage formula
payment = (principal * pow(mrate + 1, totalpayments) * mrate)/(pow(mrate + 1,totalpayments ) - 1);
mrate = rate/12; //monthly interest rate
totalpayments = term * 12; //amount of total payments
// output
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