I am having trouble trying to finish this program, What I am suppose to do is make a loop program that should ask the user for the employees number, gross pay, state tax, federal tax, and FICA withholdings. The loop will terminate when 0 is entered for the employee number. After the data is entered, the program should display totals for gross pay, state tax, federal tax, FICA withholdings, and net pay. I can't except any negative number and I can't accept the value of the state, federal, or FICA withholdings to be greater than the gross pay, if it is print the error massage

I know I don't have all of my display totals code in, but what I am having trouble is on the terminating the code if a 0 is entered for the employees number, and I am not suppose to accept any negative number for any of this program. I don't remember how to do it. Can someone please help me out.

# include <iostream>
using namespace std;
int main()
{
	int employee;
	int gross;
	int state;
	int federal;
	int FICA;

	cout << "WEhat is the employees number " << endl;
	cin >> employee;
	for ( employee = 1; employee >=, employee ++)

	cout <<"What is there gross pay" << endl;
	cin >> gross;

	cout << "What is there state tax " << endl;
	cin >> state;

	cout << "What is there federtal tax" << encl;
	cin >> federal;

	cout << "What is there FICA" << endl;
	cin >> FICA;

	if (state + federal + FICA) > gross;
	cout << "YOu are taking to much out of the persons check, please redo" << endl;

cout << " Your employee number is" << employee << endl;

	return 0;
}

Recommended Answers

All 3 Replies

Change the for-loop to a while loop, then figure out how to control and structure the loop properly. Even if this "loop"'s termination statement were written correctly, it doesn't do what you think. In general for-loops are for determinate situations, this is an indeterminate situation. Look up the difference in your textbook.

Are you sure you understand the assignment correctly? I've done a couple similar assignments that calculate the taxes and net pay automatically based on the gross pay.

This is what I got so far but I am still confused, I know it's just an extra line or two of code, but I don't have a book or anything to help me with it (except the internet ), please help

# include <iostream>
using namespace std;
int main()
{
	int employee = 1;
	int gross;
	int state;
	int federal;
	int FICA;

	cout << "WEhat is the employees number " << endl;
	cin >> employee;
	while ( employee >= );
	{
	cout << employee << "this is not an employee number" << endl;
	}
	cout <<"What is there gross pay" << endl;
	cin >> gross;

	cout << "What is there state tax " << endl;
	cin >> state;

	cout << "What is there federtal tax" << endl;
	cin >> federal;

	cout << "What is there FICA" << endl;
	cin >> FICA;

	if (state + federal + FICA) > gross;
	cout << "you are taking to much out of the persons check, please redo" << endl;

	cout << " your employee number is " << employee << endl;
	cout << " your gross pay is " << gross << endl;
	cout << " your state tax is " << state << endl;
	cout << " your federal tax is " << federal << endl;
	cout << " your FICA wihholdings are " << FICA << endl;

	return 0;
}

What parts of the program do you want to repeat? I can tell you right now that the parts that need to repeat won't, your loop is too short. If this were compilable (which it's not), you would not get the results you expect because you have placed a semi-colon after the while statement. That extraneous semi-colon terminates your loop before you even get to the statement block.

Ignoring the improper semi-colon usage, your blocking on your loop is not correct. This is the only part that that would repeat and it is an infinite loop:

while ( employee >= );    //line 13, remove the ';'
	{
	cout << employee << "this is not an employee number" << endl;
	}    //line 16

You need to move the '}' on line 16 to a much later line, around line 37. There will be some additional input statements and other control structures required, but I don't want to bog you down with all that right now.

In addition, this will not compile because you have not completed the comparison statement on line 13. Under what circumstances is the loop required to terminate?

...
The loop will terminate when 0 is entered for the employee number.
...

Look too at your if-statement on line 29. There should really be another set of parentheses there, there should also not be any semi-colon. Use of a semi-colon after most conditional statements messes up their behavior. Really, the only time there should be one there is after the "while" part of a do-while loop.

Read more about iteration structures (loops) on this page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.