# loop to alway to go back into the program

I am trying to add a loop to allow the user to re-enter the information.

#include <math.h>
#include <string>
#include <iostream>
#include <stdlib.h>

//Start of program
using namespace std;
int main(void)
{

// Set up required variables
double  loanAmount; // loan amount
int Years;          // Years of loan
double  IntRate;    // Interest rate
double MonthRate;   // Months of loans
double MonthTerm;   // Term of loan

//Infomation need for Monthly Mortgage Payment

cout << "Enter the loan amount in dollars: ";
cin >> loanAmount;

cout << "Enter the loan term in years: ";
cin >> Years;

cout << "Enter the interest rate: ";
cin >> IntRate;

// Calculate Monthly Mortgage Payment

MonthTerm = Years * 12;
MonthRate = IntRate / (12 * 100);

double PowCalc = pow(1+MonthRate,MonthTerm);
double paymentAmount = ((MonthRate*PowCalc) / (PowCalc-1)) * loanAmount;
//Information give on  Monthly Mortgage Payment
system("cls");
cout << endl;   //space
cout << "Loan amount of \$" << loanAmount << endl;
cout << endl;   //space
cout << "For a term of " << Years << " years" << " (" << Years*12 << " months)" << endl;
cout << endl;   //space
cout << "With an interest rate of " << IntRate << "%" << endl;
cout << endl;   //space
cout << "Monthly mortgage payment of \$" <<paymentAmount << " per month." << endl;
cout<<"Enter C to continue, Q to quit>";
}

while ((quit!='q')&&(quit!='Q')&&(quit!='c')&&(quit!='C') ){       //loop for check of valid user input
cout<<"Enter C to continue, Q to quit>";

cin>>quit;       //retrieve user input
cout<<'\n';
}

}
return 0;
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
You prog. is not well structured.

Intialize
quit="X";
Place while loop as
while ((quit!='q')&&(quit!='Q')&&(quit!='c')&&(quit!='C') ){
cout << "Enter the loan amount in dollars: ";
cin >> loanAmount;

cout << "Enter the loan term in years: ";
cin >> Years;

cout << "Enter the interest rate: ";
cin >> IntRate;
...

...
cout<<"Enter C to continue, Q to quit>";
}
0
Systems and Integration DeveloperCommented:
That doesn't make any sense. The loop you have will continue as long as the user doesn't enter q/Q or c/C.

Try it like:

#include <math.h>
#include <string>
#include <iostream>
#include <stdlib.h>

//Start of program
using namespace std;
int main(void)
{

// Set up required variables
double  loanAmount; // loan amount
int Years;          // Years of loan
double  IntRate;    // Interest rate
double MonthRate;   // Months of loans
double MonthTerm;   // Term of loan
char quit;

while (true)
{
//Infomation need for Monthly Mortgage Payment

cout << "Enter the loan amount in dollars: ";
cin >> loanAmount;

cout << "Enter the loan term in years: ";
cin >> Years;

cout << "Enter the interest rate: ";
cin >> IntRate;

// Calculate Monthly Mortgage Payment

MonthTerm = Years * 12;
MonthRate = IntRate / (12 * 100);

double PowCalc = pow(1+MonthRate,MonthTerm);
double paymentAmount = ((MonthRate*PowCalc) / (PowCalc-1)) * loanAmount;
//Information give on  Monthly Mortgage Payment
system("cls");
cout << endl;   //space
cout << "Loan amount of \$" << loanAmount << endl;
cout << endl;   //space
cout << "For a term of " << Years << " years" << " (" << Years*12 << " months)" << endl;
cout << endl;   //space
cout << "With an interest rate of " << IntRate << "%" << endl;
cout << endl;   //space
cout << "Monthly mortgage payment of \$" <<paymentAmount << " per month." << endl;

do
{
cout << "Enter C to continue, Q to quit>";
cin >> quit;

} while ((quit!='q') && (quit!='Q') && (quit!='c') && (quit!='C'));

if (quit == 'q' || quit == 'Q')
break;
}

cout << "Goodbye!";

return 0;
}
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Carl tawn ,
You meant ,
cin>>quit;       //retrieve user input
cout<<'\n';

It has to be the last lines of while loop, which is quite obivious .
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.