if else problem

Hello I am new to these forums and have a problem with some code I am writing for class, I have searched around and I cant seem to figure out what is going on. To me my code looks correct and according to some things I have read it looks like everything is in order but I am still getting some errors any help is greatly appreciated thanks

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
46
47
#include <cstdlib>
#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

int main(int argc, char *argv[])
{
    string lastName, firstName, employeeID;
    float totalHours, overTime, payPerHour, regularPay, doubleTime;
    float federalTaxes, stateTaxes, grossPay, netPay;
    
    cout << "Enter Last Name";
    cin >> lastName;
    cout << "Enter First Name";
    cin >> firstName;
    cout << "Enter Employee ID";
    cin >> employeeID;
    
    system("cls");
    
    cout << "Enter number of hours worked";
    cin >> totalHours;
    cout << "Enter pay per hour";
    cin >> payPerHour;
    
    doubleTime = totalHours - 40;
    
    if(totalHours <= 0)
    {
        cout << "Please enter a number greater than zero";
        cin >> totalHours;
    }
    else if(totalHours <= 40)
    {
        grossPay = totalHours * payPerHour;
        cout << grossPay <<;
    }
    else(total hours  >= 40)
    {
        grossPay = (40 * payPerHour) + (doubleTime * 2 * payPerHour);
        cout << grossPay <<;
    }
    system("PAUSE");
    return EXIT_SUCCESS;
}


The errors I get are on line 38 I am getting expected primary expression before ; token and 41 I am getting expected ; before { token. I am using devc++ if that helps any. Thanks in advance
Last edited on
closed account (zb0S216C)
Remove the semi-colons after each if/else if condition; they aren't supposed to be there.

Wazzak
Last edited on
Yea my bad I did that already but pasted in the old code. The errors previously reported are the ones without the semicolons, thank you for the reply tho going to edit first post to reflect
Last edited on
closed account (zb0S216C)
On line 38 and 43, remove the last << operator; you don't need them.

Wazzak
Last edited on
So what about the other error, I cant seemed to figure it out, does it have something to do with the doubleTime variable?
closed account (zb0S216C)
Can you post the errors?

Wazzak
It is only the error from the first post on line 41, I managed to get rid of it by switching the last else to and else if, but that doesnt seem right to me although it does compile
closed account (zb0S216C)
On line 40, close that gap between total and hours. Variables cannot contain white-space.

Wazzak
Last edited on
yea I fixed that thanks for all the help. Much appreciated, I think I got from here.
I don't believe you need the >= in line 40. A > should suffice.
Topic archived. No new replies allowed.