# Newbie Question

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 09-26-2003
bennyandthejets
That shouldn't make a difference elad.

robshirah, why didn't you take my advice? I'm pretty sure your formulae are wrong. These should be the calculations:

<40 Hours:
gross=salary*hours
tax=gross*.75

>40 Hours:
gross=(salary+1)*hours
tax=gross*.75

Using those formulae should fix any problems you're having. Plus, using my structure will make your program more efficient.

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;```
• 09-27-2003
robshirah
OK once again thanks to all who helped, I finally got it :D, here it is.

Code:

```#include <iostream.h> main() { double salary; double hours; double tax; double gross; 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; cout <<"The workers salary after taxes is: " <<tax; return 0; }```
• 09-27-2003
JaWiB
Although your code works you should really use the new headers and declare a return type for main (which would be int):
Code:

```#include <iostream> using namespace std; int main() { ...```
• 09-28-2003
Omnius
A couple of minor points.

C++ style is to declare variables at or just before the point of first use, rather than all at the start of a function or block.

Also, your program source code is a form of communication between you and any readers of the code - including yourself when you come back to it later. For that reason you need to consider whether what you've written makes sense. Although this is a trivial program, if you read through it you'll find that it includes amongst it's variables one named salary and one named tax. There is an output statement that says "The workers salary after tax is " but then, it doesn't output salary at all, it outputs tax. That suggests that you haven't named your variables in the most logical way. This is even more obvious when you consider that the value held by the variable tax isn't the amount of tax, it's the net salary. The value held by salary is the hourly rate.

Getting your program to work is one thing, but it's important also that it makes sense to someone reading it.
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12