Hello everyone. I am pretty lost when it comes to C++, but for class i have to create this mortgage calculator. I think i have this part of the assignment done, but i can not figure out how to convert either the last number, or the user input to a percentage.

So any help would be great!! Thanks everyone!

/*
 Write the program as a procedural C++ program. Calculate 
 and display the mortgage payment amount using the amount 
 of the mortgage, the term of the mortgage, and the interest 
 rate of the mortgage as input by the user. Allow the user to 
 loop back and enter new data or quit. Insert comments in the
 program to document the program.
 */


#include <iostream>
#include <cmath>


using namespace std;

int main () {
	
	double principle = 200000;
	double interest = .00575;
	int term = 30 * 12;
	double total;
	
	double monthlyInterest = interest * 12;
	
	total = (principle * monthlyInterest)/(1-pow(1 + monthlyInterest, -term));
	
	cout << "Enter Loan Amount: " <<endl;
	cin >> principle;
	
	if (principle <= 0){
		cout << "Enter valid input: ";
		cin >> principle;
	}
	
	cout << "Enter desired Interest Rate: " << endl;
	cin >> interest;
	
	if (interest <= 0) {
		cout << "Please enter a valid Interest Rate";
		cin >> interest;
		
	}	
	
	cout << "Your priniple is " << principle << endl;
	cout << "Your Interste rate is: " << interest << endl;
	cout << "Term Length: " << term << " Months" << endl;
	cout << "Your total monthly payment is: " << total << endl;
	
	
    return 0;
}

To convert decimal value to percentage you divide a value by
its max attainable value. For interest if user inputs 6 percent, the
max percent attainable is 100, so we divide 6 by 100 to get the
percentage.
Also

if (interest <= 0) {
		cout << "Please enter a valid Interest Rate";
		cin >> interest;
 
	}

You might want to make that a while loop, so until the user enters
a correct value, he gets prompted.

Thank you for the help. I dont think that i explained it well enough. I go through the program but at the end it is not giving me the correct answer. i know that the formula is correct, but i know its not right this time. (i build this program more primitive for the last assignment) I am not sure what i am doing wrong though.

Try to explain more as it's not really clear what you are trying to ask. The program compiles and is working properly. In mathematics, a percentage is nothing except division by 100. So most of the time to convert anything to percentage, you have to divide it by 100 and put % next to it.

When i compile the program, it does work. The problem is i believe it was the incorrect answer. I am not sure on how to correct this. I thought that the math was correct, but i guess not. Thanks

double interest = .00575;

I think the monthly interest is given.

double monthlyInterest = interest * 12;

is actually the yearlyInterest which comes to ~ 7 %.

Well, if you are calculating the total with the 'monthly' interest, the formula should have been

total = principle * pow(1 + interest , term);

For a constant monthly payment, divide the total by 360(the number of months).
With the default values, I got the total to be ~1.57 million ,with a monthly payment of 4376.65.

But if you are calculating annually, the total would turn to be a little less.

And you should be calculating the total after the user input

//User input
.
.
total = ...
This article has been dead for over six months. Start a new discussion instead.