Number to a percentage

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2009
Posts: 10
Reputation: hollywoood is an unknown quantity at this point 
Solved Threads: 0
hollywoood's Avatar
hollywoood hollywoood is offline Offline
Newbie Poster

Number to a percentage

 
0
  #1
Aug 12th, 2009
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!

  1.  
  2. /*
  3.  Write the program as a procedural C++ program. Calculate
  4.  and display the mortgage payment amount using the amount
  5.  of the mortgage, the term of the mortgage, and the interest
  6.  rate of the mortgage as input by the user. Allow the user to
  7.  loop back and enter new data or quit. Insert comments in the
  8.  program to document the program.
  9.  */
  10.  
  11.  
  12. #include <iostream>
  13. #include <cmath>
  14.  
  15.  
  16. using namespace std;
  17.  
  18. int main () {
  19.  
  20. double principle = 200000;
  21. double interest = .00575;
  22. int term = 30 * 12;
  23. double total;
  24.  
  25. double monthlyInterest = interest * 12;
  26.  
  27. total = (principle * monthlyInterest)/(1-pow(1 + monthlyInterest, -term));
  28.  
  29. cout << "Enter Loan Amount: " <<endl;
  30. cin >> principle;
  31.  
  32. if (principle <= 0){
  33. cout << "Enter valid input: ";
  34. cin >> principle;
  35. }
  36.  
  37. cout << "Enter desired Interest Rate: " << endl;
  38. cin >> interest;
  39.  
  40. if (interest <= 0) {
  41. cout << "Please enter a valid Interest Rate";
  42. cin >> interest;
  43.  
  44. }
  45.  
  46. cout << "Your priniple is " << principle << endl;
  47. cout << "Your Interste rate is: " << interest << endl;
  48. cout << "Term Length: " << term << " Months" << endl;
  49. cout << "Your total monthly payment is: " << total << endl;
  50.  
  51.  
  52. return 0;
  53. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,412
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 182
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso

Re: Number to a percentage

 
0
  #2
Aug 12th, 2009
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
  1. if (interest <= 0) {
  2. cout << "Please enter a valid Interest Rate";
  3. cin >> interest;
  4.  
  5. }
You might want to make that a while loop, so until the user enters
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 10
Reputation: hollywoood is an unknown quantity at this point 
Solved Threads: 0
hollywoood's Avatar
hollywoood hollywoood is offline Offline
Newbie Poster

Re: Number to a percentage

 
0
  #3
Aug 12th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 31
Reputation: group256 is an unknown quantity at this point 
Solved Threads: 1
group256 group256 is offline Offline
Light Poster

Re: Number to a percentage

 
0
  #4
Aug 12th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 10
Reputation: hollywoood is an unknown quantity at this point 
Solved Threads: 0
hollywoood's Avatar
hollywoood hollywoood is offline Offline
Newbie Poster

Re: Number to a percentage

 
0
  #5
Aug 12th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,412
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 182
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso

Re: Number to a percentage

 
0
  #6
Aug 12th, 2009
do you remember the formula for this project. It should be on your
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?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 45
Reputation: zalezog is an unknown quantity at this point 
Solved Threads: 11
zalezog zalezog is offline Offline
Light Poster

Re: Number to a percentage

 
0
  #7
Aug 12th, 2009
  1. double interest = .00575;
I think the monthly interest is given.

  1. 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

  1. 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
  1. //User input
  2. .
  3. .
  4. total = ...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC