| | |
Number to a percentage
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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!
So any help would be great!! Thanks everyone!
c++ Syntax (Toggle Plain Text)
/* 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
You might want to make that a while loop, so until the user enters
a correct value, he gets prompted.
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
C++ Syntax (Toggle Plain Text)
if (interest <= 0) { cout << "Please enter a valid Interest Rate"; cin >> interest; }
a correct value, he gets prompted.
1) What word becomes shorter if you add a letter to it?
[ Solved by : niek_e, Paul Thompson, SgtMe, murtan, xavier666, jonsca]
2) What does this sequence equal to : (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
[*solved by : murtan, xavier666]
3) What is the 123456789th prime numer? 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.
do you remember the formula for this project. It should be on your
handout.
handout.
1) What word becomes shorter if you add a letter to it?
[ Solved by : niek_e, Paul Thompson, SgtMe, murtan, xavier666, jonsca]
2) What does this sequence equal to : (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
[*solved by : murtan, xavier666]
3) What is the 123456789th prime numer?•
•
Join Date: Oct 2008
Posts: 45
Reputation:
Solved Threads: 11
C++ Syntax (Toggle Plain Text)
double interest = .00575;
C++ Syntax (Toggle Plain Text)
double monthlyInterest = interest * 12;
Well, if you are calculating the total with the 'monthly' interest, the formula should have been
C++ Syntax (Toggle Plain Text)
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
C++ Syntax (Toggle Plain Text)
//User input . . total = ...
![]() |
Similar Threads
- getting a percentage value in an asp page (ASP.NET)
- need help to solve this problem (Java)
- Weight (C++)
- Newbie question (C)
- help!! plz sum one help me FOR GOD SAKE i m crying give me solutions today (Visual Basic 4 / 5 / 6)
- round off number (C)
- freevo uses python (Python)
- Format Number as percentage. (PHP)
Other Threads in the C++ Forum
- Previous Thread: can someone tell me why it it can't read from ifstream but works with console,
- Next Thread: functions
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






