473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

C++ Mortgage Schedule...Please help!!

I am trying to get my program to compile, but it will not complete. At line 79 it states, cannot convert 'float()()' to 'float' in assignment. Here is my code.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>        
  2. #include <iomanip>
  3. #include <cmath>    
  4. #include <cctype>
  5. #include <stdlib.h>
  6. #include <sstream>    
  7.  
  8. using namespace std;
  9.  
  10. void MortSched(double, double, int);
  11.  
  12. //The structure below will contain the mortgage information
  13.  
  14. struct PaymentInfo
  15. {
  16.        float fMonPayment;
  17.        float fYears;
  18.        float fInterestRate;
  19.        float fLoanAmount;
  20.        };
  21.  
  22. int GetPayment();
  23. int LoopAgain();
  24. float UserInput();
  25. void GetPaymentInfo(PaymentInfo& payinfo);
  26. void DeterminePayment(PaymentInfo& payinfo);
  27. void ShowPayment(PaymentInfo& payinfo);
  28. char iResponse;
  29.  
  30. //The following section of code will validate user input.  We only want the user to
  31. //be able to enter numbers or the decimal.
  32.  
  33. class nondigit
  34. {
  35.       public:
  36.              bool operator() (char c)
  37.              {
  38.                   if (c =='.')
  39.                   {
  40.                         return !1;
  41.                         }
  42.                         else
  43.                         {
  44.                             return !isdigit(c);
  45.                             }
  46.                             }
  47.                             };
  48.  
  49. //This next section of code will accept the user input and validate all input
  50. //the user enters.  The main function here is to validate all user input.
  51.  
  52. float UserInput()
  53. {
  54.       float output;
  55.       string input;
  56.       cin >> input;
  57.       if (find_if(input.begin(), input.end(), nondigit()) == input.end())
  58.       {
  59.                                  stringstream mc(input);
  60.                                  mc >> output;
  61.                                  }
  62.                                  else
  63.                                  {
  64.                                      cout << input << " is not a valid number! Please try again!\n";
  65.                                      output = UserInput;
  66.                                      }
  67.                                      return output;
  68.                                      }
  69.  
  70. //The next section of code prompts the user to enter the amounts for the mortgage calculator
  71.  
  72. void GetPaymentInfo(PaymentInfo& payinfo)
  73. {
  74.      cout << "********************Mortgage Calculator********************\n";
  75.      cout << "What is the amount of the mortgage?  For example 200000\n";
  76.      payinfo.fLoanAmount = UserInput();
  77.      cout << "What is the amount of years the mortgage will be financed? For example 30\n";
  78.      payinfo.fYears = UserInput();
  79.      cout << "What is the interest rate? For example 5.75\n";
  80.      payinfo.fInterestRate = UserInput();
  81.      }
  82.  
  83. //The following code calculates the monthly payment amount based on the users input
  84.  
  85. void DeterminePayment(PaymentInfo& payinfo)
  86. {
  87.      payinfo.fMonPayment =
  88.      {
  89.                          payinfo.fLoanAmount *
  90.                          {
  91.                                              (payinfo.fInterestRate / 100) / 12 * pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12)))
  92.                                              /
  93.                                              (pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12))-1
  94.                                              }
  95.                                              }
  96.                                              };
  97.                                              }
  98.  
  99. //The following code displays the payment amount based on the users input
  100.  
  101. void ShowPayment(PaymentInfo& payinfo)
  102. {
  103.      cout << "Amount of mortgage = $\n" << payinfo.fLoanAmount <<;
  104.      cout << "Years financed = \n" << payinfo.fYears <<;
  105.      cout << "Interest Rate = \n" << payinfo.fInterestRate <<;
  106.      cout << "Monthly Payment Amount = $\n" << payinfo.MonPayment <<;
  107.      }
  108.  
  109. //The next section will allow the user to run the program again or exit the program
  110.  
  111. int LoopAgain()
  112. {
  113.     int loop = 0;
  114.     char mychar[7];
  115.     cout << "To run this program again, please press 1, and then press enter.\n";
  116.     cout << "To exit this program, please press 2, and then press enter.\n";
  117.     cin >> ws;
  118.     cin.getline(mychar,7);
  119.     if (mychar[0] == '1')
  120.     {
  121.                   cout << "Thank you for choosing option 1.  This program will run again.\n";
  122.                   run = 1;
  123.                   }
  124.                   else
  125.                   {
  126.                       cout << "Thank you for choosing option 2.  This program will now exit.\n";
  127.                       run = 0;
  128.                       }
  129.                       return run;
  130.                       }
  131.  
  132. int runGetPayment()
  133. {
  134.     float fMonPayment = 0.00;
  135.     PaymentInfo structPaymentInfo;
  136.     GetPaymentInfo(structPaymentInfo);
  137.     DeterminePayment(structPaymentInfo);
  138.     ShowPayment(structPaymentInfo);
  139.     int again = LoopAgain();
  140.     return again;
  141. }
  142.  
  143. //We will offer the user the option to view the amortization schedule
  144.  
  145. cout.setf(ios::showpoint | ios::fixed);
  146. cout.precision(2);
  147.  
  148. cout << "Would you like to view the Amortization Schedule? Press Y or N.\n";
  149. iResponse = getch();
  150. if(iResponse == 'Y' || iResponse == 'y')
  151. {
  152.    MortSched(fLoanAmount, finterestRate, fYears);
  153.             iResponse = '\n';   
  154.             }
  155.             else
  156.             {   
  157.                 iResponse = '\n';
  158.         }    
  159.         cout << endl << "Would you like to run this again? Press Y or N. ";
  160.         iResponse = getch();
  161.  
  162.     }while((iResponse == 'Y') || (iResponse == 'y'));
  163.  
  164.     return 0;
  165. }
  166. //The following code will calculate the amortization schedule.
  167.  
  168. void MortSched(double fLoanAmount, double fInterestRate, int fYears)
  169. {
  170.     double Balance, PaidInt, MonPayment, LoanAmount, Principle;
  171.     int lineCount = 0;
  172.     cout.setf(ios::left);
  173.     MonPayment = calcPayment(&LoanAmount, &InterestRate, &Years);
  174.     Balance = LoanAmount;      
  175.     for (int InstallNumber = 1; InstallNumber <= Years; ++InstallNumber)
  176.     {
  177.         if (lineCount == 0)
  178.         {
  179.             system("CLS");
  180.             cout << "Payment          Loan          Principle          Interest" << endl;
  181.             cout << "No.              Balance       Payment            Payment" << endl;
  182.             cout << "**********************************************************" << endl; 
  183.         }
  184.  
  185.         PaidInt = Balance * (InterestRate / (12 * 100));
  186.         LoanAmount = MonPayment - PaidInt;
  187.         Principle = Balance - Principle;
  188.         cout << setw(12) << InstallNumber
  189.              << setw(15) << Balance
  190.                << setw(15) << MonPayment
  191.              << setw(15) << PaidInt << endl;
  192.         Balance = Principle;        
  193.         if (lineCount==12)
  194.         {
  195.             system("pause");
  196.             lineCount = 0;
  197.                     } 
  198.                            else
  199.         {
  200.             lineCount++;
  201.         }
  202.     }
  203.  
  204.     cout.unsetf(ios::left);
  205.     return;
  206. }
  207.  
Thanks for all the help!!
Sep 18 '06 #1
3 4007
Banfa
9,065 Expert Mod 8TB
In function UserInput

output = UserInput;

should be

output = UserInput();


It would be more normal to produce this behaviour(rejecting a bad input value) using a loop rather than recursion.
Sep 18 '06 #2
I have almost got everything worked out to the end, but can you please explain to me why it is hanging on line 170?
Expand|Select|Wrap|Line Numbers
  1. MortSched(fLoanAmount, fInterestRate, fYears);
It says that fLoanAmount and the others are not declared, but I declared them in my structure at the beginning of the program? I am REALLY new to programming and so far I have been treated like an idiot from all the other forums I have asked. I am not a software person at all. I am a hardware oriented person, but of course this is one of my degree requirements. My amended code is as follows:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>        
  2. #include <iomanip>
  3. #include <cmath>    
  4. #include <cctype>
  5. #include <stdlib.h>
  6. #include <sstream>    
  7. #include <cstdlib>
  8.  
  9. using namespace std;
  10.  
  11. void MortSched(double, double, int);
  12.  
  13. //The structure below will contain the mortgage information
  14.  
  15. struct PaymentInfo
  16. {
  17.        float fMonPayment;
  18.        float fYears;
  19.        float fInterestRate;
  20.        float fLoanAmount;
  21. };
  22.  
  23. int GetPayment();
  24. int LoopAgain();
  25. float UserInput();
  26. void GetPaymentInfo(PaymentInfo& payinfo);
  27. void DeterminePayment(PaymentInfo& payinfo);
  28. void ShowPayment(PaymentInfo& payinfo);
  29. char iResponse;
  30.  
  31. //The following section of code will validate user input.  We only want the user to
  32. //be able to enter numbers or the decimal.
  33.  
  34. class nondigit
  35. {
  36.       public:
  37.              bool operator() (char c)
  38.              {
  39.                   if (c =='.')
  40.                   {
  41.                         return !1;
  42.                   }
  43.                         else
  44.                         {
  45.                             return !isdigit(c);
  46.                         }
  47.              }
  48. };
  49.  
  50. //This next section of code will accept the user input and validate all input
  51. //the user enters.  The main function here is to validate all user input.
  52.  
  53. float UserInput()
  54. {
  55.       float output;
  56.       string input;
  57.       cin >> input;
  58.       if (find_if(input.begin(), input.end(), nondigit()) == input.end())
  59.       {
  60.                                  stringstream mc(input);
  61.                                  mc >> output;
  62.       }
  63.                                  else
  64.                                  {
  65.                                      cout << input << " is not a valid number! Please try again!\n";
  66.                                      output = UserInput();
  67.                                   }
  68.                                      return output;
  69. }
  70.  
  71. //The next section of code prompts the user to enter the amounts for the mortgage calculator
  72.  
  73. void GetPaymentInfo(PaymentInfo& payinfo)
  74. {
  75.      cout << "********************Mortgage Calculator********************\n";
  76.      cout << "What is the amount of the mortgage?  For example 200000\n";
  77.      payinfo.fLoanAmount = UserInput();
  78.      cout << "What is the amount of years the mortgage will be financed? For example 30\n";
  79.      payinfo.fYears = UserInput();
  80.      cout << "What is the interest rate? For example 5.75\n";
  81.      payinfo.fInterestRate = UserInput();
  82. }
  83.  
  84. //The following code calculates the monthly payment amount based on the users input
  85.  
  86. void DeterminePayment(PaymentInfo& payinfo)
  87. {
  88.      payinfo.fMonPayment = (0);
  89.      {
  90.                          payinfo.fLoanAmount = (0);
  91.                          {
  92.                                              ((payinfo.fInterestRate / 100) / 12 * pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12)))
  93.                                              /
  94.                                              (pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12))-1);
  95.                          }
  96.       }
  97. }                                       
  98.  
  99. //The following code displays the payment amount based on the users input
  100.  
  101. void ShowPayment(PaymentInfo& payinfo)
  102. {
  103.      cout << "Amount of mortgage = $\n" << payinfo.fLoanAmount << endl;
  104.      cout << "Years financed = \n" << payinfo.fYears << endl;
  105.      cout << "Interest Rate = \n" << payinfo.fInterestRate << endl;
  106.      cout << "Monthly Payment Amount = $\n" << payinfo.fMonPayment << endl;
  107. }
  108.  
  109. //The next section will allow the user to run the program again or exit the program
  110.  
  111. int LoopAgain()
  112. {
  113.     int run = 0;
  114.     int loop = 0;
  115.     char mychar[7];
  116.     cout << "To run this program again, please press 1, and then press enter.\n";
  117.     cout << "To exit this program, please press 2, and then press enter.\n";
  118.     cin >> ws;
  119.     cin.getline(mychar,7);
  120.     if (mychar[0] == '1')
  121.     {
  122.                   cout << "Thank you for choosing option 1.  This program will run again.\n";
  123.                   run = 1;
  124.     }
  125.                   else
  126.                   {
  127.                       cout << "Thank you for choosing option 2.  This program will now exit.\n";
  128.                       run = 0;
  129.                   }
  130.                       return run;
  131. }
  132.  
  133. int runGetPayment()
  134. {
  135.     float fMonPayment = 0.00;
  136.     PaymentInfo structPaymentInfo;
  137.     GetPaymentInfo(structPaymentInfo);
  138.     DeterminePayment(structPaymentInfo);
  139.     ShowPayment(structPaymentInfo);
  140.     int again = LoopAgain();
  141.     return again;
  142. }
  143.  
  144. //We will offer the user the option to view the amortization schedule
  145. int main()
  146. {
  147. cout.setf(ios::fixed);
  148. cout.setf(ios::showpoint);
  149. cout.precision(2);
  150.  
  151.                   cout<< endl << "Would you like to view the Amortization Schedule? Press Y or N.\n";
  152.                   iResponse = getchar();
  153.  
  154. if(iResponse == 'Y' || iResponse == 'y')
  155.  
  156.    MortSched(fLoanAmount, fInterestRate, fYears);
  157.             iResponse = '\n';   
  158. }
  159.             else
  160.             {   
  161.                 iResponse = '\n';
  162.             }      
  163.         cout << endl << "Would you like to run this again? Press Y or N. ";
  164.         iResponse = getch();
  165.         do
  166.  
  167. }
  168.     while((iResponse == 'Y') || (iResponse == 'y'));
  169.  
  170.     return 0;
  171. }
  172. //The following code will calculate the amortization schedule.
  173.  
  174. void MortSched(double fLoanAmount, double fInterestRate, int fYears)
  175. {
  176.     double Balance, PaidInt, MonPayment, LoanAmount, Principle;
  177.     int lineCount = 0;
  178.     cout.setf(ios::left);
  179.     MonPayment = calcPayment(&LoanAmount, &InterestRate, &Years);
  180.     Balance = LoanAmount;      
  181.     for (int InstallNumber = 1; InstallNumber <= Years; ++InstallNumber)
  182.     {
  183.         if (lineCount == 0)
  184.         {
  185.             system("CLS");
  186.             cout << "Payment          Loan          Principle          Interest" << endl;
  187.             cout << "No.              Balance       Payment            Payment" << endl;
  188.             cout << "**********************************************************" << endl; 
  189.         }
  190.  
  191.         PaidInt = Balance * (InterestRate / (12 * 100));
  192.         LoanAmount = MonPayment - PaidInt;
  193.         Principle = Balance - Principle;
  194.         cout << setw(12) << InstallNumber
  195.              << setw(15) << Balance
  196.                << setw(15) << MonPayment
  197.              << setw(15) << PaidInt << endl;
  198.         Balance = Principle;        
  199.         if (lineCount==12)
  200.            {
  201.             system("pause");
  202.             lineCount = 0;
  203.             } 
  204.                            else
  205.         {
  206.             lineCount++;
  207.         }
  208. }
  209.  
  210.     cout.unsetf(ios::left);
  211.     return;
  212. }
Thanks for all your help!!
Sep 18 '06 #3
Banfa
9,065 Expert Mod 8TB
I have almost got everything worked out to the end, but can you please explain to me why it is hanging on line 170?
Expand|Select|Wrap|Line Numbers
  1. MortSched(fLoanAmount, fInterestRate, fYears);
It says that fLoanAmount and the others are not declared, but I declared them in my structure at the beginning of the program?
Declaring a structure does not declare data, it declares the form of the data. You then have to declare a variable of that structure type and then when you want to access members of the variable you have to use the variable name plus the member name.

Like this

Expand|Select|Wrap|Line Numbers
  1. /* Declare the structure */
  2. struct MyExampleStructure {
  3.     int iIntegerMember;
  4.     float fFloatingPointMember
  5. };
  6.  
  7. /* Declare a variable of type struct MyExampleStructure */
  8. struct MyExampleStructure mes;
  9.  
  10. /* Access the structure members of mes */
  11. mes.iIntegerMember = 10;
  12. mes.fFloatingPointMember = 1.618;
  13.  
You compiler complains about the variables in this code line
Expand|Select|Wrap|Line Numbers
  1. MortSched(fLoanAmount, fInterestRate, fYears);
because you don't actually have variables called fLoanAmount, fInterestRate or fYears.

Is that clear?
Sep 18 '06 #4

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

Similar topics

2
by: m3ckon | last post by:
Hi there, had to rush some sql and am now going back to it due to a slow db performance. I have a db for sales leads and have created 3 views based on the data I need to produce. However one...
6
by: James Walker | last post by:
Can some one help I get an error of 'checkIndate' is null or not an object can someone please help. I can't work out why Thanks in advance James <form> <td height="24" colspan="7"...
0
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web...
7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
1
by: Steve | last post by:
Hi, I've asked this question a couple of times before on this forum but no one seems to be nice enough to point me to the right direction or help me out with any information, if possible. Please...
22
by: KitKat | last post by:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7, and Cam 8. Well it does that but it also needs to change the file name to the same folder where the file is being...
17
by: Saps | last post by:
Hi all. Can anyone help me here. I have loads of .sql files and i need a way to call these from my asp page so the user can run them from the browser. Meaning i have a page with a list of all...
6
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
1
by: yello | last post by:
Hi All, I have a MS Access macro which needs to be scheduled in the Task Scheduler. I am using the following link to schedule the macro "C:\Program Files\Microsoft...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.