Good morning,

Can you guys please figure this out? I have to write a code that calculates de wage of employees on a self generated list.
User is asked for : numberofEmployees, hoursworked, rateperhour.

If the employee works 40 hrs: rate= rate * hrs
between 40 and 50 rate is 1.25
if above 50 = rate is 1.50
we are asked to calculate the grossswage then deduct 15%
Program needs to include -1 to exit

*output should look like this :

Enter number of employees: 2

Employee ID : "(1 to numberofEmployees)"
Enter total hours worked (-1 to exit )
Enter rate per hour:
NetWage is :$


Employee ID: 2 ....

and so on... until the list reaches total of number of employees or user enters -1 ..


So far this is what I have

#include <iostream>

using namespace std;

int main ()

{

	int i, k, nEmployees, employeeId;
	double hours, rate, salary;


	cout <<"\nEnter the number of employees: ";
		cin >> nEmployees;
	
	cout <<"\nEnter hours worked:  ( type -1 to end):";
		cin >> hours; 



	while (hours != -1.0) 
	{		
		// from here
		//for loops that decreases no. of employees

			for (int i = nEmployees ; i >= nEmployees ; --i ) 
			 {

			// for loop that tries to increase employee ID and displays it
			for (int k = 0 ; k > i; ++k) 
			cout <<"The employeID is: " << k <<endl; 
		// to here I dont know what I'm doing 

		cout << "\nEnter the salary per hour of the employee: ";
		cin >> rate;
	

		if (hours <= 40 ) 

			salary = hours * rate;
			
		else if (hours <= 50) ;
			salary = (1.25 * rate * (hours - 40) + rate *40);
		
	//	else ( salary > 50)
	//		salary = (rate * 1.50(hours - 50)+ rate * 10 * 1.25 + rate * 40);
		
		

		cout <<"The salary is $"<<salary * .85<<endl<<endl;

		cout <<"\nEnter hours worked:  ( type -1 to end):";
		cin >> hours; 
		
	//} end of for 

	}


	return 0;

}

I'm having huge problems here, first my logic is not working correctly nor I know the best way to attack the selection to self generate the list.

Also on the calculation side.. every thing works ok until the 3rd if else loop // where it doesnt calculates the wage for any amount of hours above 50.

If I take out //from here to here// the code compiles and at least does the calculations and the -1 escape works as well.

First of all you have an interesting problem here:

else if (hours <= 50) ;
            salary = (1.25 * rate * (hours - 40) + rate *40);

            //	else ( salary > 50)
            //

Notice the ";" after

else if (hours <= 50) ;

That's wrong :) That's why it doesn't do what you think it should and why the final "else" is seen as an error.

Suggestion for the future: up the warning level to 4 and read the warnings :)

Try this one:

int main ()
{

    int nEmployees, employeeId = 0;
    double hours, rate, salary;


    cout <<"\nEnter the number of employees: ";
    cin >> nEmployees;

    cout <<"\nEnter hours worked:  ( type -1 to end):";
    cin >> hours; 

    while ((hours != -1.0)  && (++employeeId <= nEmployees))
    {	

        cout <<"The employeID is: " << employeeId << endl; 

        cout << "\nEnter the salary per hour of the employee: ";
        cin >> rate;


        if (hours <= 40 ) 
            salary = hours * rate;
        else if (hours <= 50)
            salary = (1.25 * rate * (hours - 40) + rate * 40);
    	else
    		salary = (rate * 1.50 * (hours - 50) + rate * 10 * 1.25 + rate * 40);

        cout <<"The salary is $" << salary * .85 << endl << endl;

        cout <<"\nEnter hours worked:  ( type -1 to end):";
        cin >> hours; 

    }


        return 0;

}

But if I take everything that doesn't works in the for loops at the beginning ; and try to run only the calculations and the small menu: I get this


1>g:\libros universidad\cecs 2203 lab\lab2\lab2\lab2\lab2salary.cpp(48) : error C2146: syntax error : missing ';' before identifier 'salary'
1>g:\libros universidad\cecs 2203 lab\lab2\lab2\lab2\lab2salary.cpp(48) : error C2064: term does not evaluate to a function taking 1 arguments

I took out the ; as you recommended :
but still won't compile, also if I take out the / else ( salary > 50 )
which is also an error because the variable was supposed to be hours; I changed it but still wont get to that 3rd option.

#include <iostream>

using namespace std;

int main ()

{

	int i, k, nEmployees, employeeId;
	double hours, rate, salary;


	cout <<"\nEnter the number of employees: ";
		cin >> nEmployees;
	
	cout <<"\nEnter hours worked:  ( type -1 to end):";
		cin >> hours; 



	while (hours != -1.0) 
	{		
		// from here
		//for loops that decreases no. of employees

			//for (int i = nEmployees ; i >= nEmployees ; --i ) 
			 //{

			// for loop that tries to increase employee ID and displays it
			//for (int k = 0 ; k > i; ++k) 
			//cout <<"The employeID is: " << k <<endl; 
		// to here I dont know what I'm doing 

		cout << "\nEnter the salary per hour of the employee: ";
		cin >> rate;
	

		if (hours <= 40 ) 

			salary = hours * rate;
			
		else if (hours <= 50)
			salary = (1.25 * rate * (hours - 40) + rate *40);
		
		//else ( hours > 50)
		//salary = (rate * 1.50(hours - 50)+ rate * 10 * 1.25 + rate * 40);
		
		

		cout <<"The salary is $"<<salary * .85<<endl<<endl;

		cout <<"\nEnter hours worked:  ( type -1 to end):";
		cin >> hours; 
		
	//} end of for 

	}


	return 0;

}

Only this relational expression and you fixed what I've been tearing my hair for about 5 hours now.

while ((hours != -1.0)  && (++employeeId <= nEmployees))
{   

And this lil friend here just took out a ; and solved it. Gee that frustrates me even more.

    else if (hours <= 50)
        salary = (1.25 * rate * (hours - 40) + rate * 40);
    else
        salary = (rate * 1.50 * (hours - 50) + rate * 10 * 1.25 + rate * 40);

Guess I always take the worst approach to solve my problems something somewhat trivial.

Man, really thank you very much. That helps out a lot currently it is working the way it should.

Regards,

Jean M.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This question has already been answered. Start a new discussion instead.