C++ Problem: [Error] statement cannot resolve address of overloaded function x2 - c++

I'm a complete noob here in need of help. I'm hoping you guys, who are more experienced than me, can help me out.
Any input is greatly appreciated.
Here is how the code is supposed to go since it's too long:
#include <iostream>
using namespace std;
class Payslip
{
string name, pay_grade;
float salary, oth, otp, gross, net, tax, sss, pagibig, philhealth;
public:
void payslipdetails()
{
// Extremely long, but this part of the code would allow me to allow user to input their names, their base salary, and overtime hours.
sss = 500;
pagibig = 200;
philhealth = 100;
otp = oth * (salary*0.01);
gross = salary + otp;
net = gross - (tax + sss + pagibig + philhealth);
// then a series of if/else if condition if salary is greater/less than or equals to, and we divide the said salaries into pay grade A or B.
/* Example:
if (salary >= 10000 && salary <= 19999)
{
// Pay grade A
if (salary >= 10000 && salary <= 14999)
{
pay_grade = "A";
}
// Pay grade B
else if (salary >= 15000 && salary <= 19999)
{
pay_grade = "B";
}
tax = gross * 0.10;
}*/
}
}
void display_details()
{
cout<<"\n Employee Name : " << name;
cout<<"\n Basic Salary : " << salary;
cout<<"\n Pay Grade : " << pay_grade;
cout<<"\n No. of OT hours : " << oth;
cout<<"\n OT Pay : " << otp;
cout<<"\n Gross Pay : " << gross;
cout<<"\n Withholding Tax : " << tax;
cout<<"\n Net Pay : " << net;
}
};
int main()
{
Payslip d;
d.payslipdetails;
d.display_details;
return 0;
}
There is an error in d.payslipdetails and d.displaydetails. I hope this is more clear than my last post!
The error is: [Error] statement cannot resolve address of overloaded function
I'm not sure how to do this...

Are you possibly trying to call a method at the object d? Then you need at least add parentheses. as for each function call:
d.payslipdetails();

Check the method name
paySlipDetails(); provide any requred parameters as per implementation code of Payslip class.

Related

Parallel arrays in a loop function

I'm currently working on an assignment and it's meant to take the concept of a car body shop offering different trim packages at different prices, the program is meant to use a pretest loop to stop the function if a user inputs a code that isn't already on the array, and then the user inputs the base price of their car and the program is meant to add the base price, the trim price and a 15% sales tax and give the new user their total cost. If I only had to create a function that displayed array's I think I'd have no trouble but I'm currently tearing my hair out trying to wrap my head around how to get all the different functions to work together
currently my algorithm is
1)enter the base price of car
2.) Enter the trim package code
3.) searchIndex=0
while OptionPackageCodeArray =[search index]
searchIndex++
end loop
if searchIndex<5
input packageCode
OptionPackageCode[searchIndex] = packageCode
else
Display error "This code does not exist"
end if
4.) Determine totalCost
PackageCostArray[searchIndex] + basePrice = costwithPackage
totalCost = costwithPackage*0.15
5.) display total cost
"The price of your car with Trim is" : totalCost
end loop
and the actual C++ I have written so far is
#include <iostream>
#include <string>
using namespace std;
int main()
{
//declare variables
double basePrice = 0.00;
string OptionPackageCodeArray[] = {"BB", "SP", "NP", "HE", "UC"};
double PackageCostArray [] = {1500.00, 3250.00, 4575.00, 7500.00, 5220.00};
double totalCost = 0.00
//prompt for base price
cout << "Enter base price:";
cin>>basePrice;
cout <<"enter package code: BB, SP, NP, HE, UC";
cin >> OptionPackageCodeArray;
}
however I'm stuck at this point
if anybody has any suggestions I'd be happy to take them.
you just write the code step by step. you can read blow code for reference.
double basePrice = 0.00;
static const int num = 5;
string OptionPackageCodeArray[num] = {"BB", "SP", "NP", "HE", "UC"};
double PackageCostArray [num] = {1500.00, 3250.00, 4575.00, 7500.00, 5220.00};
double totalCost = 0.00;
while(true)
{
//prompt for base price
cout << "Enter base price:";
cin>>basePrice;
std::string package;
cout <<"enter package code: BB, SP, NP, HE, UC"<<std::endl;
cin >> package;
int i = 0;
for (; i < num; i++)
{
if (OptionPackageCodeArray[i] == package)
{
break;
}
}
if (i == num)
{
break;
}
else
{
std::cout<<(basePrice + PackageCostArray[i]) * 0.15<<std::endl;
}
}

Error in Output : C++ Carpet Store

I am working on an assignment in C++ but i am relatively new to the C++ programming language, however, I am getting errors in my output.
Question
The manager of the Crosswell Carpet Store has asked you to write a program to print customers’ bills. The manager has given you the following information:
The length and width of a room are expressed in terms of meters and centimeters. For example, the length might be reported as 16.7 meters.
The store does not sell fractions of a meter. Thus, the length and width must always be rounded up.
The carpet charge is equal to the number of square meters purchased times the carpet cost per square meter. Sales tax equal to 14% of the carpet cost must be added to the bill.
The labour cost is equal to the number of square meters purchased times R24.00, which is the labor cost per square meter. No tax is charged on labour.
Each customer is identified by a five-digit number, and that number should appear on the bill. Large-volume customers, identified by a customer number starting with a '0', may be given a discount. The discount applies to the cost before sales tax is added.
The sample output follows:
CROSWELL CARPET STORE STATEMENT
Customer name : xxxxx
Customer number : xxxxx
Carpet price : xx.xx
Labour : xx.xx
Subtotal : xx.xx
Less discount : xx.xx
Subtotal : xx.xx
Plus tax : xx.xx
Total : xx.xx
And my answer to this question is as follows:
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
using namespace std;
int calculateCarpetSize (int length, int width)
{
int carpetSize;
carpetSize = ceil(length * width);
return carpetSize;
}
float calculateCarpetCost (int carpetSize , float sellingPrice)
{
float carpetCost;
carpetCost = carpetSize * sellingPrice;
return carpetCost;
}
float calculateLabourCost(int carpetSize)
{
float labourCost;
labourCost = carpetSize * 24.00;
return labourCost;
}
bool qualifyForDiscount(string customerNo)
{
string dis = "0";
if (customerNo.compare(0, dis.length(), dis) == 0)
{
return true;
}
else{
return false;
}
}
float computeDiscount ()
{
int discountPercentage;
float discount;
cout << "Enter the Percetage Discount: ";
cin >> discountPercentage ;
discount = discountPercentage / 100;
return discount;
}
void printCustomerStatement(string customerName, string customerNo, float carpetCost, float labourCost, float discount)
{
float subtotal = carpetCost + labourCost - discount;
float vat = subtotal*0.14;
cout << "\n CROSWELL CARPET STORE"<<endl;
cout << " STATEMENT"<<endl;
cout << "Customer name : "<<customerName<<endl;
cout << "Customer number : "<<customerNo <<'\n'<<endl;
cout << "Carpet price : "<<carpetCost<<endl;
cout << "Labour : "<<labourCost <<'\n'<<endl;
cout << "Subtotal : "<<carpetCost+labourCost<<endl;
cout << "Less discount : "<<discount <<'\n'<<endl;
cout << "Subtotal : "<<subtotal<<endl;
cout << "Plus Tax : "<<vat<<endl;
cout << "Total : "<<subtotal - vat<<endl;
}
int main()
{
string customerName;
string customerNo;
float carpetSize;
float sellingPrice;
float length;
float width;
float carpetCost;
float labourCost;
float discount;
cout <<"ENTER CUSTOMER NAME:";
cin >>customerName;
cout <<"ENTER CUSTOMER NUMBER:";
cin >>customerNo;
cout <<"ENTER ROOM WIDTH:";
cin >>width;
cout <<"ENTER ROOM LENGTH:";
cin >>length;
cout <<"ENTER SELLING PRICE:";
cin >>sellingPrice;
calculateCarpetSize(length, width);
calculateCarpetCost(carpetSize, sellingPrice);
calculateLabourCost(carpetSize);
if(qualifyForDiscount(customerNo))
{
computeDiscount();
}else
{
discount = 0.00;
}
printCustomerStatement(customerName, customerNo, carpetCost, labourCost, discount);
return 0;
}
I think the problem may be my function or my datatypes, or perhaps both.
EDIT
I get an output of this sort
ENTER CUSTOMER NAME:Quatban
ENTER CUSTOMER NUMBER:02234
ENTER ROOM WIDTH:20
ENTER ROOM LENGTH:20
ENTER SELLING PRICE:35
ENTER DISCOUNT PERCENTAGE: 2
CROSWELL CARPET STORE
STATEMENT
Customer name : Quatban
Customer number : 02234
Carpet price : 1.4e+004
Labour : 9.6e+003
Subtotal : 2.4e+004
Less discount : 0
Subtotal : 2.4e+004
Plus Tax : 3.3e+003
Total : 2e+004
First
Thus, the length and width must always be rounded up
Which means your function calculateCarpetSize should look more like :
int calculateCarpetSize (float length, float width)
{
int carpetSize;
carpetSize = ceil(length) * ceil(width);
return carpetSize;
}
Then
In your main :
calculateCarpetSize(length, width);
calculateCarpetCost(carpetSize, sellingPrice);
calculateLabourCost(carpetSize);
You should be storing the result of these functions like :
carpetSize = calculateCarpetSize(length, width);
carpetCost = calculateCarpetCost(carpetSize, sellingPrice);
labourCost = calculateLabourCost(carpetSize);
Edit
This actually gives you as output :
ENTER CUSTOMER NAME:Quatban
ENTER CUSTOMER NUMBER:02234
ENTER ROOM WIDTH:20
ENTER ROOM LENGTH:20
ENTER SELLING PRICE:35
Enter the Percetage Discount: 2
CROSWELL CARPET STORE
STATEMENT
Customer name : Quatban
Customer number : 02234
Carpet price : 14000
Labour : 9600
Subtotal : 23600
Less discount : 0
Subtotal : 23600
Plus Tax : 3304
Total : 20296
This looks like your (expected ?) result, even if I believe the last line should be subtotal + tax and not subtotal - tax but I may be wrong.

Issue with calling function that takes in three parameters, one being int const [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm posting because I'm having issues figuring out why my "total aid available" is not printing the total of the pell grant, stafford loan, and work-study loan. I've tried fixing my function again and again (I used sources online and in reference book, but I don't know if the issue is that my function won't be called or not, since nothing is printing for the total aid available.
Everything else is fine, except that one thing, and it is really bugging me since no matter what changes I make, I'm in the same state. No errors showing either. I'm using microsoft visual studio for the first time as compiler, so I wonder if that is the issue.
Here is what I have:
#include <iostream>
using namespace std;
double pell_Grant(double); // forward declaration on pell_Grant ( which is a function for calculating pell grant)
double sum(double, int const, double); // declaration for sum function which gives total for the total aid available
int main()
{
double workstudy = 0, pellgrant = 5730, grossincome = 0, Total = 0; // variables
int yes;
int const stafford = 9500; //const declaration
cout << "Lemme Forecast Your FAFSA" << endl;
cout << "Enter your adjusted gross income: " << endl; cin >> grossincome; // input for gross income
if (grossincome >= 30000) // if gross income is higher than 30,000 then print message
{
cout << "Sorry Charlie, your income is too high to run this forecaster!";
return 0;
}
cout << "Can someone claim you as a dependent? [1=yes/0=no]: " << endl; // input to claim dependent or not
cin >> yes;
if (yes == 1) // if 1 for yes is selected then pell grant gets reduced by 750, if 0 or no selected, then program goes by standard procedure
{
pellgrant -= 750;
}
workstudy = 1465; // work study must be nationwide avergae 1,465
if (grossincome >= 19000) // if this condition is met then work study is not met and message is printed as follows...
{
cout << "Your Work-Study Award is not available for your income level" << endl;
workstudy = 0;
}
double foo = pell_Grant(grossincome); // value returned from pell_Grant stored here to give total
Total = sum(workstudy + stafford + pellgrant); // sum function is called and stores result in Total
if (workstudy != 0) // if work study loan isn't more than 19,000 then it will be calculated and printed in next statement
{
cout << "Your Work-Study Award (if available)= " << workstudy << endl;
}
cout << "Your Stafford Loan award (if needed)= " << stafford << endl; // prints stafford loan (const called)
cout << "Your Pell Grant= " << pellgrant << endl; // prints pell grant
cout << "Total Aid Available For You=" << Total << endl; // prints total
return (0);
}
double pell_Grant(double x) // pell_Grant function that calculates pell grant which is assigned 5,730
{
// x is gross income which is assigned 5,730. This is money received that does not need to be repaid.
if ((x > 12000) && (x < 20000)) // statement makes sure adjusted gross is bettween 12000 & 20000
{
double a = x / 1000; // for every 1,000 in adjusted gross income... reduce/subtract 400 from it
a *= 400;
x -= a;
}
if (x > 20000) // check if gross income is more than 20000
{
double a = x / 1000; // for every 1,000 in gross income, subtract 500
a *= 500;
x -= a;
}
return x;
}
double sum(double workstudy , int const stafford, double pellgrant) // function for adding up workstudy loan, stafford loan, and pellgrant loan
{
double Total;
Total = workstudy + stafford + pellgrant;
return (Total); // returns total
}
According to its declaration, the method sum() accepts 3 parameters.
double sum(double, int const, double);
But while calling you are passing only 1 parameter:
Total = sum(workstudy + stafford + pellgrant);
Instead, you need to pass 3 parameters, like this:
Total = sum(workstudy, stafford, pellgrant);
But, I don't understand why you aren't getting any errors! You are trying to call a non-existent function. You must get a compiler error.
You are calling your sum() function incorrectly. This is your code:
Total = sum(workstudy + stafford + pellgrant); // sum function is called and stores result in Total
But your sum() function has three parameters. The correct form to call the function would be:
Total = sum(workstudy, stafford, pellgrant); // sum function is called and stores result in Total

double functions, fstreams, and more fun

The big picture is to take information from one file to another file. I've done that and it works well. The next thing I need to do is find the highest value from the new file. The basic format is like this: I have a bunch of "workers", I have the days they have worked, the hours & minutes they've worked. In the new file I have it formatted to show the pay rate (I enter the value as a cin) and then I have the total amount of money they made (everyone makes the same amount.. that which is in the cin). For some reason, I cannot make a function (that works) that will extract the persons name that makes the most money, and how much money that is. I got a little frustrated and was trying whatever I could so the new function is sloppy and ridiculous, but I was hoping you could help. To keep this a general question and not a specific question, I was wondering if you guys could just explain how to do something like this (finding the highest value & outputting it WITH the name of the person.. so essentially a double for the money and a string with the persons name) using parts of my code as an example:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;
void getandprintaddress (ifstream&, ofstream&); // this function will be used to get the data from one file and input it into the next with the total amount of money made from each person as well as the next function
double highestpaid(double& highesttotal, double& totalpay, string highestpaidemp, string name); // this function is what will be used to find the highest amount of money and the person who has it
void name(); // This is to input my name in the file.
struct employees // This is the structure with all of the information that will be used to calculate everything.
{
string name; // person's name
string highestpaidemp; // highest paid employee
string address; // the address of the employee
string address2;
int days; // days worked
int hours; //hours worked
double minutes; // minutes worked
int total_hours; // total hours worked
double totalpay; // total pay
double payrate; // pay rate
double total_minutes; // minutes worked
double total_time; // total hours and minutes worked
double highesttotal; // the highest total amount of money made between all employees.
};
int main(){
ifstream inputFile;
ofstream outputFile;
getandprintaddress(inputFile, outputFile);
return 0;
}
void getandprintaddress(ifstream& inputFile, ofstream& outputFile) // the main function that will be used to get and output all the information.
{
struct employees();
ifstream getdata;
ofstream outdata;
int employees_t;
employees employeeinfo;
string inputfile;
string outputfile;
cout << "What is the name of your input file? "<<endl; // this will be the file you open
cin>>inputfile;
getdata.open(inputfile.c_str());
if(getdata.fail()){ // this is meant to be used if someone enters a file that isn't there
cout << "The input file has failed to open. \n";
exit(1);
}
cout << "What is the name of your output file? \n"; // what you want the title of the new file to be.
cin>>outputfile;
outdata.open(outputfile.c_str());
if(outdata.fail())
{
//This is if the new file is invalid
cout << "The outputfile failed to open. \n";
exit(1);
}
cout << "How many employees are there? \n" ;
cin >> employees_t; // Enter how many employees there are
cout << "What is the employees hourly payrate? \n";
cin >> employeeinfo.payrate; // how much each employee makes.
for ( int info = 0; info < employees_t; info++)
{
employeeinfo.highesttotal = 0.0; // this will be needed for calculating the highest paid employee
employeeinfo.total_minutes = 0.0; // This is needed to calculate total minutes
employeeinfo.total_hours = 0; // Same as the total_minutes, but for hours instead.
employeeinfo.total_time = 0.0; // Needed to calculate total time
string line1;
getline(getdata, employeeinfo.name);
outdata << "Name: " << employeeinfo.name <<endl; // employees name
getline(getdata, employeeinfo.address);
outdata << "Address: \n"; // Employees address
outdata<< employeeinfo.address <<endl;
getline(getdata, employeeinfo.address2);
outdata <<employeeinfo.address2 <<endl;
getdata >> employeeinfo.days;
outdata << "Days worked: " <<employeeinfo.days << endl; // Days worked
for (int totalworked=0; totalworked<employeeinfo.days; totalworked++)
{
// Because the employees work different amount of days, this loop is needed to post the individual information from each employee
getdata >> employeeinfo.hours >> employeeinfo.minutes;
employeeinfo.minutes = employeeinfo.minutes / 60;
employeeinfo.total_hours = employeeinfo.total_hours + employeeinfo.hours;
employeeinfo.total_minutes = employeeinfo.total_minutes + employeeinfo.minutes;
employeeinfo.total_time = employeeinfo.total_minutes + employeeinfo.total_hours;
employeeinfo.totalpay = employeeinfo.total_time * employeeinfo.payrate;
outdata << employeeinfo.hours <<" hours "<< employeeinfo.minutes*60 << " minutes"<< endl;
}
outdata << fixed << showpoint << setprecision(1); // Setting the total hours worked to 1 decimal so that to include the minutes
outdata << "Total hours worked: "<<employeeinfo.total_time<<endl; // Total hours worked
outdata << fixed << showpoint << setprecision(2); // Setting the decimal to two places
outdata << "Hourly pay: $"<<employeeinfo.payrate << endl; //Hourly pay
outdata << "Gross pay: $" <<employeeinfo.totalpay <<endl; // Gross pay
getline(getdata,line1);
getline(getdata,line1);
outdata << "\n";
double highestpaid(employeeinfo.highesttotal, employeeinfo.totalpay);
}
};
double highestpaid(double& highesttotal, double&totalpay, string highestpaidemp, string name)
{
if (highesttotal < totalpay)
{
highesttotal = totalpay;
highestpaidemp = name;
}
return highestpaid(double& highesttotal, double&totalpay, string highestpaidemp, string name);
};
Ok, I'm going to answer your general question rather than spend too long searching through your code, but hopefully should work for both.
You have your struct employee
Stick them all in a vector of employees (which i'll call workers)
vector<struct employee> workers
using a vector means you can just keep on adding more to the end, but an array would work too if you had a fixed number of workers
now each worker can be identified by an integer index, 0 to n-1, where n is number of workers. Now can just iterate through (quicker methods if very large number of workers but probably fine here) to find highest salary
double highestPay = 0;
int highestPaidIndex = 0;
for(int i = 0; i++; i < n)
{
if(workers[i].totalpay > highestPay)
{
highestPay = workers[i].totalpay;
highestPaidIndex = i;
}
}
Now highestPaidIndex is the index of the highest paid employee, who has name workers[highestPaidIndex].name and total earnings workers[highestPaidIndex].totalpay
Hope that solves both your general and specific question

Obtaining incorrect data using class object in different class

hey guys im writing a loan program here using two classes. I declare an object from my "MortCalc" Class in My LoanOfficer Class. The loan officer class is to determine whether a user qualifies for a loan or not a user enters the principal of a loan, monthly income, and monthly expenses. The Loan officer class then does a calculation and reports back to the user if the loan was approved using one rule. The rule is this: if the monthly payment of the loan( which is obtained from my MortCalc Class) and monthly expenses total is greater than 50% of the monthly income then the loan is not approved. The problem I've encountered is with calculating this. I try to store the calculation in a "rule" variable but it always equals 100 thus never approving the loan! obviously im doing something wrong here but i can't figure out what. here is my code:
LoanOfficer.h
class LoanOfficer
{
//private class variables
private:
MortCalc mc;
double intRate;
double monthlyIncome;
double term;
double monExpenses, principal;
double rule;
bool bLoanApprove, bOpen;
string userName, fileName,lenderName;
string loanOfficer, Welcome;
int counter;
void calculate();
LoanOfficer.cpp
LoanOfficer::LoanOfficer()
{
//initializing variables;
intRate = 4.1;
term = 30;
counter=1;
principal=0;
lenderName="John's Bank";
Welcome ="";
calculate();
}
void LoanOfficer::calculate()
{
rule = ((mc.GetMonPymt() + monExpenses) / monthlyIncome)* 100;
//i have a getter in my Mortcalc class which get's the monthly Payment.
}
bool LoanOfficer::isApproved()
{
if(rule>50)
{
bLoanApprove = true;
}
else{
bLoanApprove = false;
}
return bLoanApprove;
}
string LoanOfficer::getApproval()
{
if(bLoanApprove==true)
{
stringstream ss;
ss<<"\n\nLoan Approval Status: Yes"
<<"\nLoan amount: "
<<principal
<<"\nInterest Rate: "
<<intRate
<<"\nMonthly Payment: "
<<monPayment
<<"\nTotalLoan: "
<<mc.GetTotalLoan()
<<"\nTotal Interest"
<<mc.GetTotalInt()
<<"\n\nCongratulations We're looking to do business with you "
<<userName<<"!";
loanOfficer = ss.str();
}
else
{
stringstream ss;
ss<<"\n\nLoan Approval Status: No"
<<"\n\n Income vs Montly Payment and expenses does not meet "
<<"\n the 50% criteria net income that is necessary for this"
<<"\n institution to approve this loan";
loanOfficer = ss.str();
}
return loanOfficer;
}
void LoanOfficer::setPrincipal(double p)
{
mc.setPrin(p);
principal = p;
}
bool LoanOfficer::isOpen()
{
return bOpen;
}
void LoanOfficer::setMonInc(double mi)
{
monthlyIncome = mi;
}
void LoanOfficer::setExpenses(double ex)
{
monExpenses = ex;
}
void LoanOfficer::setAppName(string n)
{
userName = n;
}
string LoanOfficer::getFilename()
{
return fileName;
}
string LoanOfficer::getIntro()
{
stringstream ss;
ss<<"Hi Welcome to " <<lenderName
<<"\n Please enter your information below to see if you're approved for a loan."
<<"\nWe have a fixed interest rate of 4.1 and term of loan is 30 years."
<<"\nThe way we determine our loan approvals is by adding
loan payment and monthly expenses,"
<<"\nand that is greater than 50% of your monthly income the loan
is notapproved.\n\n";
Welcome = ss.str();
return Welcome;
}
void LoanOfficer::writeStatus()
{
stringstream ss;
ss<<userName<<"_"<<counter<<".txt";
fileName = ss.str();
ofstream receiptOut;
receiptOut.open(fileName.c_str());
//Writing report setting precision to 2 decimal places
//returning true if able to write receipt.
receiptOut<<" CUSTOMER LOAN INFORMATION "
<<month+1<<"/"<<day<<"/"<<year+1900<<"\n\n"
<<"********************************"
<<"\n Your Loan Information: "
<< "\n\n Principal: "<<"$" << fixed << setprecision (2)
<< principal
<< "\n\n Interest rate: "<< fixed << setprecision (2)
<< intRate << "%"
<< "\n\n Monthly Payment: "<<"$" << fixed << setprecision (2)
<< mc.GetMonPymt()
//here it obtains the correct monthly payment. I've checked through
//debugging.
<< "\n\n Total Interest paid: " <<"$"<< fixed << setprecision (2)
<< mc.GetTotalInt()
<<"\n\n Total Cost of the Loan: "<<"$" << fixed << setprecision (2)
<< mc.GetTotalLoan()
<<"\n*********************************"
<<"\n\n\nThank You for using my calculator. Have a Nice Day."
<<"\n****************************************************";
receiptOut.close();
counter++;
}
main.cpp
double principal,monthlyIncome,monthlyExpenses;
string name, answer;
string fAnswer
//class object
LoanOfficer lo;
cout<<lo.getIntro();
cout<<"Please enter your name: ";
cin>>name;
//passing name to setName class method.
lo.setAppName(name);
//start of do loop
do
{
//presenting the user a menu accessed from otherFunctions.cpp
//checking which choice user entered with switch statements
cout<<"\nPlease enter the amount you want to borrow: ";
cin>>principal;
cin.ignore();
lo.setPrincipal(principal);
cout<<"\nPlease enter your monthly income after taxes: ";
cin>>monthlyIncome;
cin.ignore();
lo.setMonInc(monthlyIncome);
cout<<"\nPlease enter your monthly expenses: ";
cin>>monthlyExpenses;
cin.ignore();
lo.setExpenses(monthlyExpenses);
cout<<lo.getApproval();
cout<<"\n\n Would you like to write a file? Enter y for yes and n for no\n";
cin>>fAnswer;
if(fAnswer =="y")
{
lo.writeStatus();
cout<<"\n\nReport is located in: "
<<lo.getFilename();
}
else
{
cout<<"\n\nNo report printed out.";
}
//ask if user would like to do another
cout<<"\n\nWould you like to do another loan? Enter y for yes and n for no\n";
cin>>answer;
cout<<"\n";
}while(answer =="y");
//end do/while
//Goodbye message
{
cout <<"\n Thanks for calculating. Goodbye!\n\n"; //when loop is done
}
return 0;
}
Change business logic!
You idea contradicts to your realization.
Let`s look closer at this statement in you question:
"The rule is this: if the monthly payment of the loan( which is obtained from my MortCalc Class) and monthly expenses total is greater than 50% of the monthly income then the loan is not approved. " and find place in your code where this business logic is implemented, here it is:
bool LoanOfficer::isApproved()
{
if(rule>50)
{
bLoanApprove = true;
}
else{
bLoanApprove = false;
}
from the code extract one can easily find that it contradicts your business logic.
Solution:
bool LoanOfficer::isApproved()
{
if(rule>50)
{
return false;
}
return true;