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. - #include <iostream>
-
#include <iomanip>
-
#include <cmath>
-
#include <cctype>
-
#include <stdlib.h>
-
#include <sstream>
-
-
using namespace std;
-
-
void MortSched(double, double, int);
-
-
//The structure below will contain the mortgage information
-
-
struct PaymentInfo
-
{
-
float fMonPayment;
-
float fYears;
-
float fInterestRate;
-
float fLoanAmount;
-
};
-
-
int GetPayment();
-
int LoopAgain();
-
float UserInput();
-
void GetPaymentInfo(PaymentInfo& payinfo);
-
void DeterminePayment(PaymentInfo& payinfo);
-
void ShowPayment(PaymentInfo& payinfo);
-
char iResponse;
-
-
//The following section of code will validate user input. We only want the user to
-
//be able to enter numbers or the decimal.
-
-
class nondigit
-
{
-
public:
-
bool operator() (char c)
-
{
-
if (c =='.')
-
{
-
return !1;
-
}
-
else
-
{
-
return !isdigit(c);
-
}
-
}
-
};
-
-
//This next section of code will accept the user input and validate all input
-
//the user enters. The main function here is to validate all user input.
-
-
float UserInput()
-
{
-
float output;
-
string input;
-
cin >> input;
-
if (find_if(input.begin(), input.end(), nondigit()) == input.end())
-
{
-
stringstream mc(input);
-
mc >> output;
-
}
-
else
-
{
-
cout << input << " is not a valid number! Please try again!\n";
-
output = UserInput;
-
}
-
return output;
-
}
-
-
//The next section of code prompts the user to enter the amounts for the mortgage calculator
-
-
void GetPaymentInfo(PaymentInfo& payinfo)
-
{
-
cout << "********************Mortgage Calculator********************\n";
-
cout << "What is the amount of the mortgage? For example 200000\n";
-
payinfo.fLoanAmount = UserInput();
-
cout << "What is the amount of years the mortgage will be financed? For example 30\n";
-
payinfo.fYears = UserInput();
-
cout << "What is the interest rate? For example 5.75\n";
-
payinfo.fInterestRate = UserInput();
-
}
-
-
//The following code calculates the monthly payment amount based on the users input
-
-
void DeterminePayment(PaymentInfo& payinfo)
-
{
-
payinfo.fMonPayment =
-
{
-
payinfo.fLoanAmount *
-
{
-
(payinfo.fInterestRate / 100) / 12 * pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12)))
-
/
-
(pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12))-1
-
}
-
}
-
};
-
}
-
-
//The following code displays the payment amount based on the users input
-
-
void ShowPayment(PaymentInfo& payinfo)
-
{
-
cout << "Amount of mortgage = $\n" << payinfo.fLoanAmount <<;
-
cout << "Years financed = \n" << payinfo.fYears <<;
-
cout << "Interest Rate = \n" << payinfo.fInterestRate <<;
-
cout << "Monthly Payment Amount = $\n" << payinfo.MonPayment <<;
-
}
-
-
//The next section will allow the user to run the program again or exit the program
-
-
int LoopAgain()
-
{
-
int loop = 0;
-
char mychar[7];
-
cout << "To run this program again, please press 1, and then press enter.\n";
-
cout << "To exit this program, please press 2, and then press enter.\n";
-
cin >> ws;
-
cin.getline(mychar,7);
-
if (mychar[0] == '1')
-
{
-
cout << "Thank you for choosing option 1. This program will run again.\n";
-
run = 1;
-
}
-
else
-
{
-
cout << "Thank you for choosing option 2. This program will now exit.\n";
-
run = 0;
-
}
-
return run;
-
}
-
-
int runGetPayment()
-
{
-
float fMonPayment = 0.00;
-
PaymentInfo structPaymentInfo;
-
GetPaymentInfo(structPaymentInfo);
-
DeterminePayment(structPaymentInfo);
-
ShowPayment(structPaymentInfo);
-
int again = LoopAgain();
-
return again;
-
}
-
-
//We will offer the user the option to view the amortization schedule
-
-
cout.setf(ios::showpoint | ios::fixed);
-
cout.precision(2);
-
-
cout << "Would you like to view the Amortization Schedule? Press Y or N.\n";
-
iResponse = getch();
-
if(iResponse == 'Y' || iResponse == 'y')
-
{
-
MortSched(fLoanAmount, finterestRate, fYears);
-
iResponse = '\n';
-
}
-
else
-
{
-
iResponse = '\n';
-
}
-
cout << endl << "Would you like to run this again? Press Y or N. ";
-
iResponse = getch();
-
-
}while((iResponse == 'Y') || (iResponse == 'y'));
-
-
return 0;
-
}
-
//The following code will calculate the amortization schedule.
-
-
void MortSched(double fLoanAmount, double fInterestRate, int fYears)
-
{
-
double Balance, PaidInt, MonPayment, LoanAmount, Principle;
-
int lineCount = 0;
-
cout.setf(ios::left);
-
MonPayment = calcPayment(&LoanAmount, &InterestRate, &Years);
-
Balance = LoanAmount;
-
for (int InstallNumber = 1; InstallNumber <= Years; ++InstallNumber)
-
{
-
if (lineCount == 0)
-
{
-
system("CLS");
-
cout << "Payment Loan Principle Interest" << endl;
-
cout << "No. Balance Payment Payment" << endl;
-
cout << "**********************************************************" << endl;
-
}
-
-
PaidInt = Balance * (InterestRate / (12 * 100));
-
LoanAmount = MonPayment - PaidInt;
-
Principle = Balance - Principle;
-
cout << setw(12) << InstallNumber
-
<< setw(15) << Balance
-
<< setw(15) << MonPayment
-
<< setw(15) << PaidInt << endl;
-
Balance = Principle;
-
if (lineCount==12)
-
{
-
system("pause");
-
lineCount = 0;
-
}
-
else
-
{
-
lineCount++;
-
}
-
}
-
-
cout.unsetf(ios::left);
-
return;
-
}
-
Thanks for all the help!!
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.
I have almost got everything worked out to the end, but can you please explain to me why it is hanging on line 170? - 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: - #include <iostream>
-
#include <iomanip>
-
#include <cmath>
-
#include <cctype>
-
#include <stdlib.h>
-
#include <sstream>
-
#include <cstdlib>
-
-
using namespace std;
-
-
void MortSched(double, double, int);
-
-
//The structure below will contain the mortgage information
-
-
struct PaymentInfo
-
{
-
float fMonPayment;
-
float fYears;
-
float fInterestRate;
-
float fLoanAmount;
-
};
-
-
int GetPayment();
-
int LoopAgain();
-
float UserInput();
-
void GetPaymentInfo(PaymentInfo& payinfo);
-
void DeterminePayment(PaymentInfo& payinfo);
-
void ShowPayment(PaymentInfo& payinfo);
-
char iResponse;
-
-
//The following section of code will validate user input. We only want the user to
-
//be able to enter numbers or the decimal.
-
-
class nondigit
-
{
-
public:
-
bool operator() (char c)
-
{
-
if (c =='.')
-
{
-
return !1;
-
}
-
else
-
{
-
return !isdigit(c);
-
}
-
}
-
};
-
-
//This next section of code will accept the user input and validate all input
-
//the user enters. The main function here is to validate all user input.
-
-
float UserInput()
-
{
-
float output;
-
string input;
-
cin >> input;
-
if (find_if(input.begin(), input.end(), nondigit()) == input.end())
-
{
-
stringstream mc(input);
-
mc >> output;
-
}
-
else
-
{
-
cout << input << " is not a valid number! Please try again!\n";
-
output = UserInput();
-
}
-
return output;
-
}
-
-
//The next section of code prompts the user to enter the amounts for the mortgage calculator
-
-
void GetPaymentInfo(PaymentInfo& payinfo)
-
{
-
cout << "********************Mortgage Calculator********************\n";
-
cout << "What is the amount of the mortgage? For example 200000\n";
-
payinfo.fLoanAmount = UserInput();
-
cout << "What is the amount of years the mortgage will be financed? For example 30\n";
-
payinfo.fYears = UserInput();
-
cout << "What is the interest rate? For example 5.75\n";
-
payinfo.fInterestRate = UserInput();
-
}
-
-
//The following code calculates the monthly payment amount based on the users input
-
-
void DeterminePayment(PaymentInfo& payinfo)
-
{
-
payinfo.fMonPayment = (0);
-
{
-
payinfo.fLoanAmount = (0);
-
{
-
((payinfo.fInterestRate / 100) / 12 * pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12)))
-
/
-
(pow((payinfo.fInterestRate / 100) / 12 + 1, (payinfo.fYears * 12))-1);
-
}
-
}
-
}
-
-
//The following code displays the payment amount based on the users input
-
-
void ShowPayment(PaymentInfo& payinfo)
-
{
-
cout << "Amount of mortgage = $\n" << payinfo.fLoanAmount << endl;
-
cout << "Years financed = \n" << payinfo.fYears << endl;
-
cout << "Interest Rate = \n" << payinfo.fInterestRate << endl;
-
cout << "Monthly Payment Amount = $\n" << payinfo.fMonPayment << endl;
-
}
-
-
//The next section will allow the user to run the program again or exit the program
-
-
int LoopAgain()
-
{
-
int run = 0;
-
int loop = 0;
-
char mychar[7];
-
cout << "To run this program again, please press 1, and then press enter.\n";
-
cout << "To exit this program, please press 2, and then press enter.\n";
-
cin >> ws;
-
cin.getline(mychar,7);
-
if (mychar[0] == '1')
-
{
-
cout << "Thank you for choosing option 1. This program will run again.\n";
-
run = 1;
-
}
-
else
-
{
-
cout << "Thank you for choosing option 2. This program will now exit.\n";
-
run = 0;
-
}
-
return run;
-
}
-
-
int runGetPayment()
-
{
-
float fMonPayment = 0.00;
-
PaymentInfo structPaymentInfo;
-
GetPaymentInfo(structPaymentInfo);
-
DeterminePayment(structPaymentInfo);
-
ShowPayment(structPaymentInfo);
-
int again = LoopAgain();
-
return again;
-
}
-
-
//We will offer the user the option to view the amortization schedule
-
int main()
-
{
-
cout.setf(ios::fixed);
-
cout.setf(ios::showpoint);
-
cout.precision(2);
-
-
cout<< endl << "Would you like to view the Amortization Schedule? Press Y or N.\n";
-
iResponse = getchar();
-
-
if(iResponse == 'Y' || iResponse == 'y')
-
-
MortSched(fLoanAmount, fInterestRate, fYears);
-
iResponse = '\n';
-
}
-
else
-
{
-
iResponse = '\n';
-
}
-
cout << endl << "Would you like to run this again? Press Y or N. ";
-
iResponse = getch();
-
do
-
-
}
-
while((iResponse == 'Y') || (iResponse == 'y'));
-
-
return 0;
-
}
-
//The following code will calculate the amortization schedule.
-
-
void MortSched(double fLoanAmount, double fInterestRate, int fYears)
-
{
-
double Balance, PaidInt, MonPayment, LoanAmount, Principle;
-
int lineCount = 0;
-
cout.setf(ios::left);
-
MonPayment = calcPayment(&LoanAmount, &InterestRate, &Years);
-
Balance = LoanAmount;
-
for (int InstallNumber = 1; InstallNumber <= Years; ++InstallNumber)
-
{
-
if (lineCount == 0)
-
{
-
system("CLS");
-
cout << "Payment Loan Principle Interest" << endl;
-
cout << "No. Balance Payment Payment" << endl;
-
cout << "**********************************************************" << endl;
-
}
-
-
PaidInt = Balance * (InterestRate / (12 * 100));
-
LoanAmount = MonPayment - PaidInt;
-
Principle = Balance - Principle;
-
cout << setw(12) << InstallNumber
-
<< setw(15) << Balance
-
<< setw(15) << MonPayment
-
<< setw(15) << PaidInt << endl;
-
Balance = Principle;
-
if (lineCount==12)
-
{
-
system("pause");
-
lineCount = 0;
-
}
-
else
-
{
-
lineCount++;
-
}
-
}
-
-
cout.unsetf(ios::left);
-
return;
-
}
Thanks for all your help!!
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? - 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 -
/* Declare the structure */
-
struct MyExampleStructure {
-
int iIntegerMember;
-
float fFloatingPointMember
-
};
-
-
/* Declare a variable of type struct MyExampleStructure */
-
struct MyExampleStructure mes;
-
-
/* Access the structure members of mes */
-
mes.iIntegerMember = 10;
-
mes.fFloatingPointMember = 1.618;
-
You compiler complains about the variables in this code line - MortSched(fLoanAmount, fInterestRate, fYears);
because you don't actually have variables called fLoanAmount, fInterestRate or fYears.
Is that clear?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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"...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
| |