By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

Loops to Allow users to go back and enter new data or just quit

P: 10
I am working on an assignment where I have to allow end-users to enter in data and to have C++ make a calculation. From there I have to set up a loop to allow users to go back and enter new data or just quit. I have the part down where the users are entering in information to get a calculation, but I am not understanding the part about looping to go back, any direction will be greatly appreciated. Here is my code for now:
//************************************************** *****
//Program: Calculations Payments
//Purpose: To calculate a mortgage monthly payment by the user entering input
// and to allow the user to enter new data if they wish or to just quit the program.
//Programmer: Cameron Faldeti
//Date: 10/30/06
//School: University of Phoenix
//Class: POS 440: Introduction To C++
//Instructor: John Williams
#include <iostream>
#include <iomanip>
#include <cmath> //Header file in order for a user to calculate math formulas
using namespace std;
int main()
{

//Variable declarations
double LoanAmount; //Loan amount entered by the user in order to calculate a mortgage monthly payment
int term; //Years entered by user to use for calcuating the monthly payment
double InterestRate; //Interest Rate in percentage used for the loan amount
double MortgageMonthlyPayment;
cout << "Enter a loan amount: ";
cin >> LoanAmount;
cout << "Loan amount is: $ " << LoanAmount << endl;
cout << "Enter Interest rate: ";
cin >> InterestRate;
cout << "Interest rate is: " << right << setw(8) <<InterestRate << "%" << endl << endl;
cout << "Enter term: ";
cin >> term; // Total years for paying off mortgage loan
cout << "Your term is: " << right << setw(2) << term << " years" << endl << endl;
//Mortgage monthly calculation
MortgageMonthlyPayment = (LoanAmount* pow((1+ InterestRate/100/12),term*12)* InterestRate/100/12)/((pow((1+InterestRate/100/12),term*12))-1); //Calculates the monthly mortgage payment
cout << "Mortgage monthly payment is: $ " << MortgageMonthlyPayment << endl;
//Allow user to loop back and enter new data or to just quit the program
while (letter != 'Q' && letter != 'Z')
return 0; //End of program
}
Nov 1 '06 #1
Share this Question
Share on Google+
1 Reply


100+
P: 143
try this:

#include <iostream>
#include <iomanip>
#include <cmath> //Header file in order for a user to calculate math formulas


using namespace std;

//******************************main()************** **********************
int main()
{

//Variable declarations
double LoanAmount; //Loan amount entered by the user in order to calculate a mortgage monthly payment
int term; //Years entered by user to use for calcuating the monthly payment
double InterestRate; //Interest Rate in percentage used for the loan amount
double MortgageMonthlyPayment;

char repeat = 'y';
while (repeat == 'y' || repeat == 'Y')
{

cout << "Enter a loan amount: ";
-
-
- Body of your program
-
-
-
cout << "Mortgage monthly payment is: $ " << MortgageMonthlyPayment << endl;

//Allow user to loop back and enter new data or to just quit the program
cout<<"would you like to enter another set of data: (y/n)"<<endl;
cin>>repeat;
}


return 0; //End of program
}
Nov 1 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.