473,770 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Mortgage Schedule...Plea se help!!

11 New Member
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 4036
Banfa
9,065 Recognized Expert Moderator Expert
In function UserInput

output = UserInput;

should be

output = UserInput();


It would be more normal to produce this behaviour(rejec ting a bad input value) using a loop rather than recursion.
Sep 18 '06 #2
promiscuoustx
11 New Member
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 Recognized Expert Moderator Expert
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
1930
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 o the views, which has subqueries to the other views is VERY slow and it needs to be speeded up, but am unsure how, can anyone help... below is the sql?
6
1803
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" valign="top"><form name="booknow"><select
0
1702
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 browser that Hotmail does not support. If you continue to use your current browser software we cannot guarantee that Hotmail will work correctly for you". Please help, this is very annoying. I have been searching for help on
7
2392
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 me. This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of our text. I have done Exercise 7 for you: Below you will find the ADT specification for a string of characters. It represents slightly more that a minimal string...
1
1388
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 help me out with this because this is a very serious issue for me and I need to learn more about this. And here it is again: I've been running postgres on my server for over a year now and the tables have become huge. I have 3 tables that have...
22
2201
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 grabbed, BUT it doesn't. I have tried and tried.....please help example: C:\Projects\Darryl\Queue Review Files\2-24\Cam 7\Cam7-20060224170000-01.jpg Cam7 but all I keep getting is Cam1, as the beginning of the jpg name,...:( HELP!
17
2289
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 scripts. each when clicked i am able to run the script. so HOW and what do i do to call and run the .sql Thanks
6
3326
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, EmpName,DeptID,DateOfJoin, Sal, Addr) Finance (EmpID, Sal) Club (Clubname, EmpID, Fee, DateOfJoin) Leave (EmpID, Date) Department (DeptID, DeptName, NoOfEmployees)...
1
2401
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 Office\OFFICE11\MSACCESS.EXE" "D:\Formatting Script.mdb" /x "Schedule_Macro" The macro is scheduled and ran fine when I used my User Id in the Schedule Task.
0
9617
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9453
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8929
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.