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 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.
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
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? - 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 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?
|
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
|
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
|
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...
|
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...
| |
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!
|
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
|
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)...
|
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.
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |