Need help with coding

I am currently new to computer programming and I have to write a program for my class. I need to write a program that calculate the gross pay an employee earns. the employee makes 16.78 an hour and if he works over 40 weeks he gets paid 1.5 times that rate. if the worker has 3 or more dependents 35 dollars is taken out of the wage. in the end, 25% is taken away in tax. I will post my code below. When I go to compile (g++ compiler) it says that it expected an "if" before my "else" but I have an if before the else. Any hep is appreciated.


#include <iostream>
using namespace std;

int main()
{
//declarations
int hours, dependents;
double grossPay, rate;
cout << "Enter the hourly rate of pay: $";
cin >> rate;
cout << "Enter the number of hours worked,\n";
cin >> hours;

if (hours > 40);
{
grossPay = rate * hours * 1.5;
}
else
{
grossPay = rate * hours;
}

cout << "Enter the number of dependents,\n";
cin >> dependents;

if (dependents >= 3)
{
grossPay = (grossPay - 35) * 0.75;
}
else
{
grossPay = grossPay * 0.75;
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout << "If you worked\n";
cout << hours;
cout << "And you have\n";
cout << dependents;
cout << "Then you have\n";
cout << "Gross pay:$" << grossPay << endl;
return 0;
}

A couple of things:

1. You'll get more help if you post C++ related questions in the Beginners or General C++ sections. I'd recommend Beginners.

2. PLEASE learn to use code tags, they make reading and commenting on source code MUCH easier.

HINT: you can edit your post and add the code tags.

http://www.cplusplus.com/articles/jEywvCM9/

With that said, adding code tags to your code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;

int main()
{
   //declarations
   int hours, dependents;
   double grossPay, rate;
   cout << "Enter the hourly rate of pay: $";
   cin >> rate;
   cout << "Enter the number of hours worked,\n";
   cin >> hours;

   if (hours > 40);
   {
      grossPay = rate * hours * 1.5;
   }
   else
   {
      grossPay = rate * hours;
   }

   cout << "Enter the number of dependents,\n";
   cin >> dependents;

   if (dependents >= 3)
   {
      grossPay = (grossPay - 35) * 0.75;
   }
   else
   {
      grossPay = grossPay * 0.75;
   }
   cout.setf(ios::fixed);
   cout.setf(ios::showpoint);
   cout.precision(2);

   cout << "If you worked\n";
   cout << hours;
   cout << "And you have\n";
   cout << dependents;
   cout << "Then you have\n";
   cout << "Gross pay:$" << grossPay << endl;
   return 0;
}

Line 14, if (hours > 40);, remove the semi-colon. The semi-colon at the end of the if statement terminates the block.
Oh my god man thank you so much. You have no idea how long I've been working on this
An errant semi-colon is one of the more common beginner (and not-so beginner) problems, and can be hard to notice. I do have an idea of how long it has been kicking you. :)

BTDT more often than I care to remember or admit.

Reading the ENTIRE error message usually helps to locate the problem. The source of the error might not be at the exact line the compiler says it is at. Look a few lines up and lo!
Topic archived. No new replies allowed.