ples forum. .

Hello forum,

I seem to be having trouble compiling this program. . I get 3 different errors for the same 2 lines.

1) [Error] stray '\226' in program
2) [Error] '(pay + ((long long unsigned int)(((long long unsigned int)count) * 32ull)))->EmployeePay::gross' cannot be used as a function
3) [Error] expected ')' before numeric constant

*Lines are underlined and bolded

#include <iostream>
#include <iomanip>
using namespace std;

const float CONST_STATE_TAX = 0.05;
const float CONST_FED_TAX = 0.15;
const float CONST_UNION_FEES = 0.02;
const int NUM_EMPLOYEES = 5;
const int NAME_LENGTH = 20;
const int ID_LENGTH = 6;
typedef char String[NAME_LENGTH];

struct EmployeeInfo{
String firstname;
char middleinitial;
String lastname;
String idnumber;
};

struct EmployeePay{
float rate;
float overtime;
float gross;
float state_tax;
float fed_tax;
float union_fees;
float net;
float hours;
};

void Input(EmployeeInfo[], EmployeePay[]);
void Calculate(EmployeePay[]);
void Output(EmployeeInfo[], EmployeePay[]);
void OutputFile(EmployeeInfo[], EmployeePay[]);

int main()
{
EmployeeInfo info[NUM_EMPLOYEES];
EmployeePay pay[NUM_EMPLOYEES];

Input(info, pay);
Calculate(pay) ;
Output(info, pay);
OutputFile(info, pay);
return 0;
}

void Input(EmployeeInfo info[], EmployeePay pay[])
{
for (int count; count < NUM_EMPLOYEES; count++)
{
cout << "Please enter student #" << (count + 1) << " first name: ";
cin.getline(info[count].firstname, NAME_LENGTH);
cout << "Please enter student #" << (count + 1) << " middle initial: ";
cin >> info[count].middleinitial;
cout << "Please enter student #" << (count + 1) << " last name: ";
cin.getline(info[count].lastname, NAME_LENGTH);
cout << "Please enter student #" << (count + 1) << " id number: ";
cin.getline(info[count].idnumber, NAME_LENGTH);
cout << "Please enter student #" << (count + 1) << " hourly pay rate: ";
cin >> pay[count].rate;
while (pay[count].rate < 0)
{
cout << "Invalid hourly pay. You must enter a rate greater than '0'."
<< " Enter a rate: ";
cin >> pay[count].rate;
}
cout << "Please enter student #" << (count + 1) << " total hours worked: ";
cin >> pay[count].hours;
while (pay[count].hours > 60 || pay[count].hours < 40)
{
cout << "Invalid hours worked. You cannot work more than 60 or"
<< " less than 40 hours per week. Enter hours worked: ";
cin >> pay[count].hours;
}
cin.ignore();
}
}

void Calculate(EmployeePay pay[])
{
for (int count; count < NUM_EMPLOYEES; count++)
{
pay[count].overtime = ((pay[count].hours) – 40.00);
pay[count].gross = ((pay[count].rate * 40.00) + ((pay[count].overtime) * (pay[count].rate * 1.50)));
pay[count].state_tax = (CONST_STATE_TAX * pay[count].gross);
pay[count].fed_tax = (CONST_FED_TAX * pay[count].gross);
pay[count].union_fees = (CONST_UNION_FEES * pay[count].gross);
pay[count].net = ((pay[count].gross) – ((pay[count].state_tax) + (pay[count].fed_tax) + (pay[count].union_fees)));
}
}

void Output(EmployeeInfo info[], EmployeePay pay[])
{

cout <<"Student Records " << endl;
cout << setfill('=') << setw(143) << '\0' << setfill(' ') << endl;
cout << left << setw(13) << "First Name" << setw(13) << "Middle Initial" << setw(13) << "Last Name" << setw(13)
<< "Id Number" << setw(13) << "Rate" << setw(13) << "Overtime" << setw(13) << "Gross" << setw(13) << "State Tax"
<< setw(13) << "Fed Tax" << setw(13) << "Union Fees" << setw(13) << "Net" << endl;
cout << setfill('=') << setw(143) << '\0' << setfill(' ') << endl;

for (int count; count < NUM_EMPLOYEES; count++)
{
cout << setw(13) << info[count].firstname;
cout << setw(13) << info[count].middleinitial;
cout << setw(13) << info[count].lastname;
cout << setw(13) << info[count].idnumber;
cout << setw(13) << pay[count].rate;
cout << setw(13) << pay[count].overtime;
cout << setw(13) << pay[count].gross;
cout << setw(13) << pay[count].state_tax;
cout << setw(13) << pay[count].fed_tax;
cout << setw(13) << pay[count].union_fees;
cout << setw(13) << pay[count].net;
cout << setfill('-') << setw(143) << '\0' << setfill(' ') << endl;
}
}
Replace – with -.
The stray character is the wrong sort of '-'.
The usual cause is using a word-processor rather than a plain text editor (or an editor designed for writing code).

The usual minus sign typed on the keyboard is - but the code contains – instead. The first is ASCII code 45, the second ASCII code 226. If you use a word processor, it "helpfully" changes the characters that you type into some other completely different (but perhaps visually similar) character.

Solution.
1. use a suitable code or text editor
2. change this:
pay[count].overtime = ((pay[count].hours) 40.00);
to this:
pay[count].overtime = ((pay[count].hours) - 40.00);

While we're here, there are lots of unnecessary parentheses around everything here, the code works correctly (and is easier to read) without them,
pay[count].overtime = pay[count].hours - 40.00;

That same comment applies to all the lines in that part of the code.

The main thing to remember is that multiplication and division take precedence over addition and subtraction

For example, 2 * 3 + 4 * 5 will be interpreted as (2 * 3) + (4 * 5)
Generally, it's not necessary to include to use parentheses unless you want to change the default interpretation.


One more error. This function has a prototype declaration:
void OutputFile(EmployeeInfo[], EmployeePay[]);
but the actual function body is not defined.

Last edited on
@Chervil I appreciate the quick and detailed response. Thank you
Topic archived. No new replies allowed.