ERROR "cannot convert 'float' to 'float...'..." - c++

There are probably other little formatting errors in here that I'll need to fix, etc. but what I need help with is what to do with the following:
Lab8pt1.cpp: In function 'float Salary(float, float)':
Lab8pt1.cpp:48: error: assignment of function 'float Salary(float, float)'
Lab8pt1.cpp:48: error: cannot convert 'float' to 'float ()(float, float)' in assignment
Lab8pt1.cpp:50: error: assignment of function 'float Salary(float, float)'
Lab8pt1.cpp:50: error: cannot convert 'double' to 'float ()(float, float)' in assignment
Lab8pt1.cpp:51: error: cannot convert 'float (*)(float, float)' to 'float' in return
I know it's referring to my Salary function, but I'm not sure what the issue with my float is. This is just supposed to be a simple Lab Assignment that teaches us how to use functions (we only have to write the code for the functions, the rest was given to us).
Help, please! Thanks in advance!
#include <iostream>
#include <iomanip>
#include <string>
using namespace std ;
void Header(void) ;
float Salary(float Hours, float Pay_Rate);
void Print_it(float Hours,float Pay_Rate,float Sal, float Tax_Rate, string Name);
void Read(float &hour, float &Pay_R,string &name) ;
bool Verify(float Hours, float Pay_Rate);
int main ( void )
{
float Pay_Rate, Hours, Sal, Tax;
const float Tax_Rate= (float)0.09 ;
string name;
Header();
for(int i = 0 ; i < 3 ; i++){
Read(Hours,Pay_Rate,name);
Sal = Salary(Hours,Pay_Rate);
Print_it(Hours,Pay_Rate,Sal, Tax_Rate,name);
}
cout<<"\n\n\n**********\t End of report \t*****\n\n\n\n";
return 0 ;
}
void Header( void )
{
string name;
cout << "Welcome, " << name << ", to the Salary Calculator: a program that will calculate your salary.";
return;
}
float Salary(float Hours, float Pay_Rate)
{
if( Hours <= 40 )
Salary = Hours * Pay_Rate;
else if( Hours > 40)
Salary = Hours * (Pay_Rate * 1.5);
return(Salary);
}
void Print_it(float Hours,float Pay_Rate,float Sal, float Tax_Rate, string Name)
{
cout << fixed << setprecision(2);
cout << "Name: " << left << setw(15) << Name << endl;
cout << "Hours worked: " << left << setw(15) << Hours << endl;
cout << "Pay rate: " << left << setw(15) << Pay_Rate << endl;
cout << "Tax rate: " << left << setw(15) << Tax_Rate << endl;
cout << "Salary: " << left << setw(15) << Sal << endl;
return;
}
void Read(float &hour, float &Pay_R,string &name)
{
cout << "Please enter your name: ";
getline(cin, name);
cout << "Please enter number of hours worked: ";
cin >> hour;
cout << "Please enter your pay rate: ";
cin >> Pay_R;
return;
}
bool Verify(float Hours, float Pay_Rate)
{
if( Hours < 0 || Hours > 60 || Pay_Rate < 0 || Pay_Rate > 500)
return false;
else
return true;
}

Salary = Hours * Pay_Rate;
Salary is the function name. You can not assign a float value to it. You need to declare a float variable and return that variable.
float sal;
sal = Hours * Pay_Rate;
return sal;
In fact you don't need this variable. You can directly return within the if-else block.
if( Hours <= 40 )
return Hours * Pay_Rate;
Note that method and variable names should start with a lowercase letter, class name should start with uppercase. This is widely used convention.

its the function you are trying to return.
float Salary(float Hours, float Pay_Rate)
{
if( Hours <= 40 )
Salary = Hours * Pay_Rate;
else if( Hours > 40)
Salary = Hours * (Pay_Rate * 1.5);
return(Salary);
}
there is no variable salary defined in this function
Corrected code is:
float Salary(float Hours, float Pay_Rate)
{
float salary;
if( Hours <= 40 )
salary = Hours * Pay_Rate;
else if( Hours > 40)
salary = Hours * (Pay_Rate * 1.5);
return(salary);
}

Related

C++ Expression preceding parentheses

I'm currently working on a set of code where we had to rework the code from all being written in the main and breaking it up into two subfunctions and the main. I've broken it up, but I am having trouble reading in one of my subfunctions. I never learned parameter passing in depth because my professor only briefly touched on it.
The error I'm getting is "Expression preceding parentheses of apparent call must have (pointer-to-) function type."
This is the line of code I'm having an issue with:....
type = selectCarpet(type, unitPrice);
unitPrice = oneRoom(pricePerSqYd, count, ftLength, ftWidth, ftSq, ydSq, squareYd, materialCost, totalCost, unitPrice);
and this is the function:
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string>
using namespace std;
const double BEST = 6.99,
MEDIUM = 4.59,
BASIC = 3.50,
INSTALL = 129.99;
const int NINE = 9;
int selectCarpet(int type, int unitPrice);
double oneRoom(double pricePerSqYd, int count, double ftLength, double ftWidth, int numRooms, double ftSq, double ydSq, int squareYd, double materialCost, double unitPrice, double totalCost);
int main()
{
double ftLength, // room length in feet
ftWidth, // room width in feet
ftSq, // square footage
ydSq, // square yard
materialCost, // carpet material cost
totalCost, // material cost plus install
grandTotal,
unitPrice;
int squareYd, // square yards, round off
type, // carpet type
count,
numRooms;
type = 0;
unitPrice = 0;
double pricePerSqYd,
oneRoom;
type = selectCarpet(type, unitPrice);
totalCost = 0;
cout << "\nEnter number of rooms: ";
cin >> numRooms;
unitPrice = oneRoom(pricePerSqYd, count, ftLength, ftWidth, ftSq, ydSq, squareYd, materialCost, totalCost, unitPrice);
// step 11
grandTotal = 0;
grandTotal += totalCost;
cout << "\n\nThe grand total price is "
<< grandTotal << endl;
// step 13
do
{
cout << "\n\t\t*** CARPET INSTALLATION ***\n\n";
cout << "Select carpet type:\n"
<< "1 - Best Quality, Unit Price $6.99\n"
<< "2 - Medium Quality, unit price $4.59\n"
<< "3 - Basic Quality, Unit price $3.50\n"
<< "4 - exit\n"
<< "Enter your choice --> ";
cin >> type;
} while (type != 1 && type != 2 && type != 3 && type != 4);
return 0;
}
int selectCarpet(int type, int unitPrice)
{
do
{
cout << "\n\t\t*** CARPET INSTALLATION ***\n\n";
cout << "Select carpet type:\n"
<< "1 - Best Quality, Unit Price $6.99\n"
<< "2 - Medium Quality, unit price $4.59\n"
<< "3 - Basic Quality, Unit price $3.50\n"
<< "4 - exit\n"
<< "Enter your choice --> ";
cin >> type;
} while (type != 1 && type != 2 && type != 3 && type != 4);
while (type != 4)
{
// step 2
if (type == 1) unitPrice = BEST;
else if (type == 2) unitPrice = MEDIUM;
else if (type == 3) unitPrice = BASIC;
}
return unitPrice;
}
double oneRoom(double pricePerSqYd, int count, double ftLength, double ftWidth, int numRooms, double ftSq, double ydSq, int squareYd, double materialCost, double unitPrice, double totalCost)
{
for (count = 0; count < numRooms; count++)
{
cout << "Enter room length in feet: ";
cin >> ftLength;
cout << "Enter room diwth in feet: ";
cin >> ftWidth;
// step 5
ftSq = ftLength * ftWidth;
// step 6
ydSq = ftSq / NINE;
// step 7
squareYd = int(ydSq + .5);
// step 8
materialCost = squareYd * unitPrice;
// step 9
totalCost = materialCost + INSTALL;
// step 10
cout << setiosflags(ios::fixed | ios::showpoint)
<< setprecision(2);
cout << "\n\nSquare footage of the room is: " << ftSq
<< "\nSquare yard of the room is:\t" << ydSq
<< "\nSquare yards priced for: " << squareYd
<< "\nMaterial Cost:\t$" << materialCost
<< "\nInstallation\t$" << INSTALL
<< "\nTotal Cost\t$" << totalCost
<< endl << endl;
}
return pricePerSqYd;
}
any help is appreciated as I have almost no idea what I am doing here. Thank you.
This declaration within main():
double pricePerSqYd,
oneRoom;
shadows the declaration of your function outside of main():
double oneRoom(..., ...);
Name lookup finds the variable first, but you can't call a double. Hence the error. Just rename one or the other.

My code is returning two really weird errors

My code isn't working. I don't know why. The errors I am getting don't make sense.
17 18 C:\Users\the beast\Desktop\Case study phase 3.0.6.cpp [Error] a function-definition is not allowed here before '{' token
I dont even know why it throwing this error.
77 1 C:\Users\the beast\Desktop\Case study phase 3.0.6.cpp [Error] expected '}' at end of input
^ all brackets are present checked no idea why it is throwing this error
#include<iostream>
#include<fstream>
#include<string>
#include<cstdlib>
using namespace std;
//loading libraries
float const taxnet = .9;
float const taxwh = .1;
float employeenumber;
float payrate=0;
float gross=0;
float net=0;
float manhours=0;
float overtime=0;
float taxes=0;
char usercontrols;
void data_loop(char usercontrols);
void writeWorkerInfo(ofstream &stream, float employeenumber, float manhours, float payrate, float gross, float taxes, float net);
void payrollcalc(float employeenumber, float manhours, float payrate, float gross, float taxes, float net);
void data_entry(float employeenumber, float manhours, float payrate);
void data_recall(float employeenumber);
void data_error_check(char usercontrols);
int main(){
// varibles
cout << "Hit 1 to enter new data; hit 2 load a file; hit escpae to exit." << endl;
cin >> usercontrols;
while (usercontrols != 27){
data_error_check(usercontrols);
}
return 0;
}
void data_error_check(char usercontrols){
cin >> usercontrols;
if(usercontrols == 49 || 50){
data_loop(usercontrols);
}
else if (usercontrols != 49 ||50){
cout << "Wrong button hit enter to return to main menu" << end;
cin >> usercontols;
if(usercontrols == 13){
main();
}
}
}
void data_loop(char usercontrols){
cin >> usercontrols;
if (usercontrols == 49){
data_entry();
}
else(usercontrols == 50){
data_recall();
}
}
void writeWorkerInfo(ofstream &stream, float employeenumber, float manhours, float payrate, float gross, float taxes, float net){
stream << " Your ID is " << employeenumber << endl;
stream << " # of hours worked " << manhours << endl;
stream << " Your Hourly rate is " << payrate << endl;
stream << " Your Gross pay is " << gross << endl;
stream << " Your tax rate is " << taxwh << endl;
stream << " Amount of taxes " << taxes << endl;
stream << " Your net pay is " << net << endl;
data_loop();
}
void payrollcalc(float employeenumber, float manhours, float payrate, float gross, float taxes, float net){
if (manhours > 40) {
overtime = manhours - 40;
gross = ((manhours - overtime) * payrate) + ((payrate * 1.5)* overtime);
//overtime claculation
}
else {
gross = manhours * payrate;
//no overtime calculation
}
taxes = gross * taxwh;
net = gross * taxnet;
//writeWorkerInfo(float employeenumber,float manhours,float payrate,float gross,float taxwh,float taxes,float net);
std::string empnum = std::to_string(employeenumber);
ofstream payroll;
payroll.open(empnum + ".txt");
writeWorkerInfo(float employeenumber,float manhours,float payrate,float gross,float taxes,float net);
payroll.close();
}
void data_entry(float employeenumber,float manhours,float payrate){
cout << "Enter Employee ID:";
cin >> employeenumber;
cout << "Enter Number of Hours Worked:";
cin >> manhours;
cout << "Enter Pay rate:";
cin >> payrate;
payrollcalc();
}
void data_recall(float employeenumber){
cout << "Enter employee number";
cin >> employeenumber;
///reading in data
std::string empnum = std::to_string(employeenumber);
ofstream payroll;
payroll.open(empnum + ".txt");
payroll.close();
data_loop();
}
Just get the functions definitions out of the main block code and call them inside main
These points should explain why it's not working:
The function main() needs to return a type.
You are defining all your functions inside main(), place them above main or below with function prototypes.
You are using variables inside functions that aren't declared yet.
Funtions are made so that it can be used in defferent place of the program, making it inside the main scope makes less sense!
Moreover we can't define funtion inside another function, we can just call it from nother fuction that comes after its declaration!
2ndly your main says nothing about returning.
ReturnType FunctionName (dataType args, ...){ FuntionBody}
Refer to the above syntax of a funtion declaration.
A function must always provide its return type as prefix or void if it dont return anything!
Note: In some compiler void main() works just fine, but some compiler says main should return something. So as a standard method you must define main as int not void to safegaurd urself.

expected unqualified-id before int

I got this error "expected unqualified-id before int" in c++ when I was trying to compile it.
void yearlyWithdrawal(int startingAge, int numOfYears), int yearlyAmount, double interestRate)
{
int age = startingAge;
int lastAge = startingAge + numOfYears;
double cash = yearlyAmount;
cout << "Age | Yearly Plan" << endl;
cout << "----+----------------" << endl;
while (age <= lastAge)
{
cout.width(3);
cout << age << " | ";
cout.width(15);
cout.precision(2);
cout.setf(ios::fixed);
cout << cash << endl;
if (age != lastAge)
cash = cash + cash*interestRate / 100.0;
age++;
}
system("pause");
}
I tried to find what went wrong but couldn't.
Hint:
void yearlyWithdrawal(int startingAge, int numOfYears), int yearlyAmount, double interestRate)
// --------------------------------------------------^
void yearlyWithdrawal(int startingAge, int numOfYears), int yearlyAmount, double interestRate)
The ) in the middle of this line could be an obvious pointer to a problem before 'an int'.

C++: Mock Catering Company Billing Program - Not able to ouput bad data to error file

This program is basically supposed to read data from a file, and then process that data depending on what it is. It's sort of a mock catering company, and the variables are number of adults, number of children, type of meal (deluxe or standard), type of day (weekend [Yes or No], initial deposit, etc. and the surcharge, tax, total, etc. are calculated in the CalcData function depending on what that data is (i.e. If it is a deluxe meal (D or S), the price is $25.80, instead of $21.75 (for Standard), if it is a weekend (Y or N), the surcharge is added up to the total bill, and discounts are given, depending on the total amount).
Although I think I am overusing references in my functions, the program has worked fine without the error checking part (i.e. check that the input was/is valid - No negatives for amount of adults/children/initial deposit, no other letters than S/D and/or Y/N, etc.). I initially used an "isValid" function that would return a bool, and an "outputErrorFile" function, and use an if/else in main - If the data was invalid, then output to the error file, and if it wasn't invalid, then just to output it to the "Billing Statement" text file. I since combined the two in a "checkValid" function. Does the same thing, I think, so there's no need to have two separate functions.
Right now it is outputting everything to the error file (specifically, the bool variable, "valid," is constantly false on all of my data). I'm sure I'm doing something stupid in there. I don't really care about what is output to the console, only care about what is output to the text files...Thanks for looking.
Thanks.
INPUT FILE (adults, children, deluxe or standard meal, weekend (Y/N), Initial Deposit):
10 0 S Y 100.00
27 3 D Y 57.50
125 17 D N 0.00
4 0 S N 25.00
0 25 S Y 23.75
250 43 D N 500.00
0 0 D N 0.0
10 0 R Y 10.00
17 3 D R 15.00
5 0 D Y 275.00
-3 10 D Y 20.00
14 -1 S N 30.00
20 3 D Y -10.00
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void getData(int &, int &, char &, char &, float &);
void checkValid(int &, int &, char &, char &, float &, bool &);
void calcData(int, int, char, char, float, float &, float &, float &, float &);
void sendData(int, int, char, char, float, float &, float &, float &, float &);
ifstream inFile;
ofstream outFile("Billing_Statement.txt");
ofstream error_Report("Error_Report.txt");
//Declare the tax rate and weekend surcharge as constants.
const float taxRate = 0.18;
const float weekendSurcharge = .07;
int main()
{
bool valid = true;
float mealCost;
float totalTax;
float totalSurcharge;
float discountAmount;
int numAdults;
int numChildren;
char mealType;
char dayType;
float depositAmount;
cout << "\nThis program will calculate data for a catering company " << endl;
outFile << " Adults " << "Children " << "Meal " << " Weekend " << setw(9) << "Deposit "
<< setw(6) << "Tax" << setw(11) << "Surcharge" << setw(10) << "Discount" << setw(12) <<
"Meal Cost" << endl;
error_Report << " Adults " << "Children " << "Meal " << " Weekend " << setw(9) <<
"Deposit " << endl;
inFile.open("file.txt");
if (!inFile) {
cout << "nError: File could not be opened. ";
exit(1);
}
while (!inFile.eof()) {
getData(numAdults, numChildren, mealType, dayType, depositAmount);
checkValid(numAdults, numChildren, mealType, dayType, depositAmount, valid);
if (valid == true)
{
calcData(numAdults, numChildren, mealType, dayType, depositAmount, totalTax,
totalSurcharge, discountAmount, mealCost);
sendData(numAdults, numChildren, mealType, dayType, depositAmount, mealCost,
totalTax, totalSurcharge, discountAmount);
}}
cout << "\nA copy of this has created for your convenience in the file,
\"Billing_Statement.txt \"" << endl;
inFile.close();
outFile.close();
error_Report.close();
return 0;
}
void getData(int &numAdults, int &numChildren, char &mealType, char &dayType, float
&depositAmount)
{
inFile >> numAdults >> numChildren >> mealType >> dayType >> depositAmount;
}
void checkValid(int &numAdults, int &numChildren, char &mealType, char &dayType, float
&depositAmount, bool & valid)
{
if (numAdults < 0 || numChildren < 0)
valid = false;
else if (mealType != 'D' || mealType != 'S')
valid = false;
else if (dayType != 'Y' || dayType != 'N')
valid = false;
else if (depositAmount < 0)
valid = false;
else
valid = true;
if (valid == false) {
error_Report << setw(7) << numAdults << setw(9) << numChildren << setw(6) << mealType <<
setw(9) << dayType << setw(9) << right << depositAmount << setw(8) << endl;
}
}
void calcData(int numAdults, int numChildren, char mealType, char dayType, float
depositAmount, float &totalTax, float &totalSurcharge, float &discountAmount, float
&mealCost)
{
if (mealType == 'S') {
mealCost = ((numAdults * 21.75) + (numChildren * (21.75 * .60)));
totalTax = mealCost * taxRate;
mealCost += taxRate;
if (dayType == 'Y') {
totalSurcharge = mealCost * weekendSurcharge;
mealCost += totalSurcharge;
}}
else {
mealCost = ((numAdults * 25.80) + (numChildren * (25.80 * .60)));
totalTax = mealCost * taxRate;
mealCost += taxRate;
if (dayType == 'Y') {
totalSurcharge = mealCost * weekendSurcharge;
mealCost += totalSurcharge;
}
}
if (mealCost < 100) {
discountAmount = .015 * mealCost;
mealCost -= discountAmount;
}
else if (mealCost >= 100 && mealCost < 400) {
discountAmount = .025 * mealCost;
mealCost -= discountAmount;
}
else if (mealCost >= 400) {
discountAmount = .035 * mealCost;
mealCost -= discountAmount;
}
}
void sendData(int numAdults, int numChildren, char mealType, char dayType, float
depositAmount, float &mealCost, float &totalTax, float &totalSurcharge, float
&discountAmount)
{
outFile << fixed << showpoint << setprecision(2);
outFile << setw(7) << numAdults << setw(9) << numChildren << setw(6) << mealType <<
setw(9) << dayType << setw(9) << right << depositAmount << setw(8) << totalTax <<
setw(10) << totalSurcharge << setw(10) << right << discountAmount << setw(12) << right
<< mealCost << endl;
}
It seems your checks for types, e.g.
mealType != 'D' || mealType != 'S'
will always yield true and, thus, valid is always set to false. You probably meant
!(mealType == 'D' || mealType == 'S')
or rewritten with Boolean logic
mealType != 'D' && mealType != 'S'
BTW, there are other things wrong in your program, too. For example, there is on of my pet peeves: using file.eof() to control an input loop is always wrong! You will either process the last line twice or, if there is a misformatted input somehwere, end up with an infinite loop. You always need to check after trying to read if the input was successful! The stream cannot possibly know ahead of time what you will be trying to read and if that is going to be successful.

How do I fix my while Error?

I'm writing a program in Microsoft Visual Studio with C++ that will retrieve information from a .txt file. In that file there are negative numbers, but when I try to write a while loop that states what to do if there is a negative number, I get several errors.
Can someone please help me with this? Here is my code and I do realize there are errors but I can't figure out how to write the While loop statement to read these values which are hours worked and the hourly rate from the .txt file
Sample text file:
45.0 10.50
-35.0 7.75
50.0 12.00
45.0 -8.50
30.0 6.50
48.0 -10.25
-50.0 10.00
50.0 8.75
40.0 12.75
56.0 8.50
Code:
//*****************************
// This program is to help calculate an employee's weekly gross pay as well as
// the net pay while showing the taxes that were taken off.
// The data that will be shown will be calculated from a .txt file
// that was created and called employee.txt.
// Input: Will be the inFile known as employee.txt
// Output: Gross pay, taxable income, federal tax, state tax, and net pay
// Typed by:
// Date:
//******************************
#include <iomanip>
#include <fstream>
#include <iostream>
using namespace std;
float computeGross(float, float);
void computeTaxes(float, float&, float&, float&);
float computeNetPay (float&, float&, float&, float&);
const float hours = 40; // Regular 40 hour work week
const float ovTime = 1.5; // Overtime if hours go over 40
const float exemption = 200.0; // Exemption if pay goes over 200
const float fedTaxRate = 0.10; // Federal Tax Rate
const float stTaxRate = 0.03; // State Tax rate
ifstream inFile;
ofstream outFile;
int main()
{
inFile.open("employee.txt");
outFile.open("result.txt");
float hours, rate, grossPay, taxableIncome, fedTax, stTax, NetPay;
inFile >> hours >> rate;
while(inFile)
{
if {
(hours <= 0)&& (rate <= 0);
outFile << "Invalid Data";
}
else{
return 0;
}
}
grossPay = computeGross(hours, rate);
computeTaxes (grossPay, taxableIncome, fedTax, stTax);
computeNetPay (grossPay, fedTax, stTax, NetPay);
outFile << fixed << showpoint << setprecision(2);
outFile << "Hours worked = " << hours << endl
<< "Hourly rate = " << rate << endl
<< "Employee's gross pay = " << grossPay << endl
<< "Taxable Income = " << taxableIncome << endl
<< "Federal Taxes = " << fedTax << endl
<< "State Taxes = " << stTax << endl
<< "Net Pay = " << NetPay << endl;
return 0;
}
float computeGross (float h, float r) //Computes for the Gross Pay
{
if (h > hours)
return hours * r + (h - hours) * r * ovTime;
else
return h * r;
}
void computeTaxes(float g, float& taxable, float& fedTax, float& stTax) //Computes both Taxes
{
taxable = g - exemption;
if (taxable > 0.0)
{
fedTax = fedTaxRate * taxable;
stTax = stTaxRate * taxable;
}
else
{
fedTax = 0.0;
stTax = 0.0;
}
}
float computeNetPay (float& grossPay, float& fedTax, float& stTax, float& NetPay)
{
return NetPay = grossPay - fedTax - stTax;
}
In your main function you have:
while(inFile)
{
if ((hours <= 0) && (rate <= 0))
{
outFile << "Invalid Data";
}
else {
return 0;
}
}
When the else is triggered the program finishes, the main function returns. You might want a continue break or nothing here instead, that return statement ends the main function not the While loop.
To get all the data out of the file your read statement ( inFile >> hours >> rate);
will need to be in this or another loop. Say after the IF test for validity, it could be in the Else.
while(inFile)
{
if ((hours <= 0) && (rate <= 0)) {
outFile << "Invalid Data";
}
else {
// call the data functions
// save the returned values
}
//prime hours and rate for the next loop
inFile >> hours >> rate;
}
Well.. my guess is this is what your looking for:
Note that the:
if ((hours <= 0) && (rate <= 0))
is changed to:
if ((hours <= 0) || (rate <= 0))
otherwise it won't ever hit the "invalid data" with your supplied data
//*****************************
// This program is to help calculate an employee's weekly gross pay as well as
// the net pay while showing the taxes that were taken off.
// The data that will be shown will be calculated from a .txt file
// that was created and called employee.txt.
// Input: Will be the inFile known as employee.txt
// Output: Gross pay, taxable income, federal tax, state tax, and net pay
// Typed by:
// Date:
//******************************
#include <iomanip>
#include <fstream>
#include <iostream>
using namespace std;
float computeGross(float, float);
void computeTaxes(float, float&, float&, float&);
float computeNetPay (float&, float&, float&, float&);
const float hours = 40; // Regular 40 hour work week
const float ovTime = 1.5; // Overtime if hours go over 40
const float exemption = 200.0; // Exemption if pay goes over 200
const float fedTaxRate = 0.10; // Federal Tax Rate
const float stTaxRate = 0.03; // State Tax rate
int main()
{
ifstream inFile ("employee.txt");
ofstream outFile ("result.txt");
float hours, rate, grossPay, taxableIncome, fedTax, stTax, NetPay;
if (inFile.is_open())
{
while (! inFile.eof() )
{
inFile >> hours;
inFile >> rate;
if ((hours <= 0) || (rate <= 0))
{
outFile << "Invalid Data";
}
else
{
grossPay = computeGross(hours, rate);
computeTaxes (grossPay, taxableIncome, fedTax, stTax);
computeNetPay (grossPay, fedTax, stTax, NetPay);
outFile << fixed << showpoint << setprecision(2);
outFile << "Hours worked = " << hours << endl
<< "Hourly rate = " << rate << endl
<< "Employee's gross pay = " << grossPay << endl
<< "Taxable Income = " << taxableIncome << endl
<< "Federal Taxes = " << fedTax << endl
<< "State Taxes = " << stTax << endl
<< "Net Pay = " << NetPay << endl;
}
}
}
return 0;
}
The rest is the same
For a start, I think that this:
if {
(hours <= 0)&& (rate <= 0);
outFile << "Invalid Data";
}
Should be this:
if ((hours <= 0) && (rate <= 0)) {
outFile << "Invalid Data";
}
Note that to get code to format properly on StackOverflow, you should only use spaces, not tabs. I think that's whats causing your format issues.