1. ## Newbie Question

I want to get the workers salary, then display the salary after taxes are taken out(salary divided by 25%). So I need to know the correct way to divide salary by 25% then make it into a variable called net. Thanks alot.

net = salary / 25%

2. 25percent = 0.25 so you need to make all your variables double...
Code:
```double net = 0;
double salary = 0;
double tax = .25;
//set salary and other things that your program does
/*:ooops!*/net = ( salary*tax );```
axon

3. net = slaray*.25;

4. Thanks alot

5. int salary, net; // defines two integer variables

You don't want to "divide by 25%" ! You need to multiply by 0.25 to get the tax. tax = salary * 0.25; Then, you can subtract this from the salary.

The cleanest way to do this would be to multiply the salary by 0.75 to get the net directly.

It would also be "better" (more flexable) to make the tax rate a variable: float TaxRate = 0.25 ; Then, calculate net = Salary * (1-TaxRate) ;

If you want to show dollars and cents, you'll need to use float rather than int.

I hope that gets you started. If you have problems, post your code. And, if you haven't done so yet, read the board guidelines. They will tell you to use a clear-specific title for your posts, and to post whatever code you have so far. Also see the post regarding code tags. This will tell you how to post your code.

6. I did as you suggested, net = salary/tax; , with salary input at 100 it gives me an answer of 400????? For some reason it seems to be multiplying (salary)100 times 25

double salary; //workers hourly wage
double net; //workers wage after taxes are taken out
double tax; //ammount of taxes to be subtracted from salary
tax = (.25);
cout <<"Please input workers salary: ";
cin >>salary;
cout <<"\n";
net = salary/tax;
cout <<"Here is workers salary after taxes: "<<net;
return 0;

7. Dougdbug you nailed it, thanks alot, & thanks to everyone for the help.

8. ## Glad I could help !

Computer problems are alot like math word-problems.

There are two problems to solve when writing a program. First, you have to figure out how to solve the problem (the formula or algorithm). Then, you have to figure out how to make the program do it for you.

In this case it would have been helpful to try-out the formula with a calculator first... I should have sugggested that. If you have a slightly more complicated formula, a spreadsheet might be a better way to try it out.

When things get really complicated, or really long (with looping etc.), it's easier to go ahead and write the program and try-out your formula/algorithm in the program.

9. I have another problem here, I added hours & overtime into the program, overtime pay being salary+1, if over 40 hours. it compiles correctly but it takes the last dollar & rounds up, 41*11 = 451, 451 * .75 = 338.25. When I run the program it comes up with 339 as the gross after taxes answer?!?!

double salary; //workers hourly wage
double gross;
double tax;
double hours;

cout <<"Please enter workers total hours: ";
cin >>hours;
cout <<"\n";

cout <<"Please input workers salary: ";
cin >>salary;
cout <<"\n";

gross = salary*hours;

if (hours <= 40)
tax = gross*.75;
else
gross = (salary+1) * hours;
tax = (gross+1) *.75;

cout <<"Workers gross pay is: "<<gross<<endl;
cout <<"Here is workers salary after taxes: "<<tax;
return 0;

11. Your problem occurs because you haven't placed braces around your over 40 hour code:
Code:
```if (hours <= 40)
tax = gross*.75;
else
gross = (salary+1) * hours;
tax = (gross+1) *.75;```
This code means that your after tax salary is always calculated based on (gross+1). Change it to this:
Code:
```if (hours <= 40)
tax = gross*.75;
else
{
gross = (salary+1) * hours;
tax = (gross+1) *.75;
}```
Then it works fine.

12. Can I ask why you calculate >40 hours tax based on (gross+1)? Shouldn't the tax always be just 75% of gross earnings? I would do it like this:
Code:
```cout <<"Please enter workers total hours: ";
cin >>hours;
cout <<"\n";

cout <<"Please input workers salary: ";
cin >>salary;
cout <<"\n";

if (hours <= 40)
gross = salary*hours;
else
gross = (salary+1) * hours;

tax = gross*.75;```
Besides being more correct (IMO), that code is actually faster (technically) and more efficient.

13. robshira: I suggest always using braces...even when you are only executing a single line/item. It is a good hait to get into at an early stage. It saves debugging time when your programming assignemnts get LARGE! so for the if else always use braces:
Code:
```if ( condition ) {
//stuff......
} else if ( condition2 ) {
//more stuff.....
} else { //default
//some more....
}```

14. Ok, first of all id like to thank all those that helped : ) Now, I still have the same problem, the code is adding 40+ hours(overtime pay) to be more than it acually is.

Code:
```#include <iostream.h>

main()

{

double salary; //workers hourly wage
double gross;
double tax;
double hours;
cout <<"Please enter workers total hours: ";
cin >>hours;
cout <<"\n";

cout <<"Please input workers salary: ";
cin >>salary;
cout <<"\n";

gross = salary*hours;

if (hours <= 40)
tax = gross*.75;
else
{
gross = (salary+1) * hours;
tax = (gross+1) *.75;
}

cout <<"Workers gross pay is: "<<gross<<endl;
cout <<"Here is workers salary after taxes: "<<tax;
return 0;
}```

15. Code:
```if (hours <= 40)
tax = gross*.75;
else
{
gross = (salary+1) * hours;
tax = (gross+1) *.75;
}

review the above like you have posted vs below

if (hours <= 40)
{
net = gross*.75;
}
else
{
gross = (salary+1) * hours;
net = gross *.75;
}```