1. Need some newb pointers

I have tried to code this project but I am having trouble, I think I am close but no cigar. No this is not homework! I finished that and chose to attempt this one from my book on my own. Can anyone show me my issues and explain why I am not code compliant? Any help is greatly appreciated thank you in advance for advise:

Written directives from my book were as follows:

Design a program that computes pay for employees. Allow a user to continuously input employees’ names until an appropriate sentinel value is entered. Also input each employee’s hourly wage and hours worked. Compute each employee’s gross pay (hours times rate), withholding tax percentage (based on the accompanying table), withholding tax amount, and net pay (gross pay minus withholding tax). Display all the results for each employee. After the last employee has been entered, display the sum of all the hours worked, the total gross payroll, the total withholding for all employees, and the total net payroll.

Weekly Gross Pay Withholding Percent

(%)
0.00 – 200.00 10
200.01 – 350.00 14
350.01 – 500.00 18
500.01 – up 0 22

Code:
```//Program: Payroll Report
//PayrollReport.cpp
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
string empName;
int *salary = 0;
int hrsWorked = 0;
int x = 0;
int grossPay = 0;
int withTax = 0;
int netPay = 0;
int totalGrossPay = 0;
int totalHrsWorked = 0;
int totalWithTax = 0;
int totalNetPay = 0;
string QUIT = "zzzz";
const int SIZE = 4;
double WITH_RATE[SIZE] = {0.10, 0.14, 0.18, 0.22};
double WITH_RANGE[SIZE] = {0, 200.01, 350.01, 500.01};
int main()
{
cout << "Enter an employee name or ", QUIT, " zzzz ";
cin >> empName;

while (empName != QUIT)
{
cout << "enter", empName, "'s hourly wage and hours worked";
cin >> *salary, hrsWorked;
grossPay = hrsWorked * *salary;
totalHrsWorked = totalHrsWorked + hrsWorked;
totalGrossPay = totalGrossPay + grossPay;
x = SIZE -1;
}
while (grossPay < WITH_RANGE[x]){
x = x -1;
}
withTax = (grossPay * WITH_RATE[x]);
endwhile
totalWithTax = totalWithTax + withTax;
netPay = grossPay - withTax;
totalNetPay = totalNetPay + netPay;
cout << empName, grossPay, WITH_RATE[x] * 100, withTax, netPay;
cout << "Enter an employee name or ", QUIT, " zzzz ";
cin >> empName;
}
endwhile
cout << totalHrsWorked, totalGrossPay, totalWithTax, totalNetPay;
return 0;
system("PAUSE");

}```

3. endwhile is not declared or initialized. Maybe you meant that as a comment to show where the while statements end but it needs // in front if that is the case or just delete them entirely. You also have an extra } before the second endwhile. Are you trying to use pointers? Because you declared int *salary to be a pointer but you never assign it another variables address. I would suggest not making it a pointer b/c it doesn't have to be but if you want practice then check out this tutorial on pointers first to see how to set them up. Here's the link

4. Originally Posted by Fandango21
endwhile is not declared or initialized. Maybe you meant that as a comment to show where the while statements end but it needs // in front if that is the case or just delete them entirely. You also have an extra } before the second endwhile. Are you trying to use pointers? Because you declared int *salary to be a pointer but you never assign it another variables address. I would suggest not making it a pointer b/c it doesn't have to be but if you want practice then check out this tutorial on pointers first to see how to set them up. Here's the link
Thank you for your response.......... I was begining to think the post was a wash due to the overwhelming snobi-ness that seems to seeth under the brilliant crowds feet. Yours is a welcome pointer. I tip my hat to you sir!

5. Code:
```cout << "Enter an employee name or ", QUIT, " zzzz ";
...
cout << "enter", empName, "'s hourly wage and hours worked";
cin >> *salary, hrsWorked;
...
cout << empName, grossPay, WITH_RATE[x] * 100, withTax, netPay;
cout << "Enter an employee name or ", QUIT, " zzzz ";
...
cout << totalHrsWorked, totalGrossPay, totalWithTax, totalNetPay;```
What's with all those commas in your I/O? I'm certain that you don't want to be doing that. Do you mean to use <</>>?

6. Why all the global variables? You only have one function, put them inside the function. Using global variables is a bad practice that leads to hard to maintain, hard to troubleshoot programs.

Jim

7. Here's your code I modified that you can look at and kind of see with better indentations,working while loop and such. Let me know if you have any questions about the changes.

Code:
```#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cmath>

using namespace std;

int main() {

string empName;
int x = 0;
double salary, hrsWorked, grossPay, withTax, netPay, totalGrossPay = 0, totalHrsWorked = 0, totalWithTax = 0, totalNetPay = 0;
string QUIT = "zzzz";
const int SIZE = 4;
double WITH_RATE[SIZE] = {0.10, 0.14, 0.18, 0.22};
double WITH_RANGE[SIZE] = {0, 200.01, 350.01, 500.01};

cout << "Enter an employee name or " << QUIT << " to quit: ";
cin >> empName;

while (empName != QUIT) {
cout << "Enter " << empName << "'s hourly wage: ";
cin >> salary;
cout << "Enter " << empName << "'s hours worked: ";
cin >> hrsWorked;

grossPay = hrsWorked * salary;
totalHrsWorked = totalHrsWorked + hrsWorked;
totalGrossPay = totalGrossPay + grossPay;
x = SIZE -1;

while (grossPay < WITH_RANGE[x]) {
x = x -1;
}

withTax = (grossPay * WITH_RATE[x]);
totalWithTax = totalWithTax + withTax;
netPay = grossPay - withTax;
totalNetPay = totalNetPay + netPay;

cout << "Employee: " << empName << endl;
cout << "Gross Pay: " << grossPay << endl;
cout << "With Rate: " << WITH_RATE[x] * 100 << endl;
cout << "With Tax: " << withTax << endl;
cout << "Net Pay: " << netPay << endl;
cout << endl;

cout << "Enter an employee name or " << QUIT << " to quit: ";
cin >> empName;

}

cout << "Total Hours: " << totalHrsWorked << " " <<
"Total Gross Pay: " << totalGrossPay << " " <<
"Total With Tax: " << totalWithTax << " " <<
"Total Net Pay: " << totalNetPay << endl;
cout << endl;

system("PAUSE");
return 0;

}```

8. Thanks a million sir!!

Fandango you are an impressive code writer! You did in a few moments what would have been a lifetime of work for me. I am new to this and inspired by your helpful insights...... I shall study your work over the next few weeks and try to aspire to your inspirational work! I tip my hat and if we should meet I would like to buy you a nice steak and as much alcohol you could handle at the nearest gentlemans club!!

Like I said I am new to this but fascinated by the sheer power programmers weild with their very fingertips. Bravo sir I owe you sir! I would like to seek your help in the future and I am sure you are a very busy man indeed. I am assuming you do this for a living.... Best Wishes and many thanks for answering many of my coding questions as an engineer once said to me it's the devil in the details! You ROCK!!

9. No problem. I'm still learning C++ myself, and coding in general, but glad I could help.

10. I tip my hat and if we should meet I would like to buy you a nice steak and as much alcohol you could handle at the nearest gentlemans club!!
I really should post more ;->

11. You both need to improve your indentation.

12. I was begining to think the post was a wash due to the overwhelming snobi-ness that seems to seeth under the brilliant crowds feet.
Just a note, this is not the way to ingratiate yourself to people who are volunteering to help you and others, and do so every day.