Help with getting positive values

So I have written a payroll program and am using if statements to obtain a for hours work, it seems to work correctly but if you enter a negative value, the program ask you to enter a value greater than 0 and less than or equal to 60, then if you enter a number greater than 40 your gross pay ends up being negative some how and I dont understand why it happens. Maybe it has something to do with how the doubleTime variable is defined because that is the only time it occurs, any help is greatly appreciated

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#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\n";
    cin >> lastName;
    cout << "Enter First Name\n";
    cin >> firstName;
    cout << "Enter Employee ID\n";
    cin >> employeeID;
    
    system("cls");
    
    cout << "Enter number of hours worked\n";
    cin >> totalHours;
    
    doubleTime = totalHours - 40;
    
    if(totalHours <= 0)
    {
        cout << "Please enter a number greater than zero but less than or equal to sixty\n";
        cin >> totalHours;
    }
    else if(totalHours > 60)
    {
        cout << "Please enter a number greater than zero but less than or equal to sixty\n";
        cin >> totalHours;
    }
    cout << "Enter pay per hour\n";
    cin >> payPerHour;
    if(payPerHour <= 0)
    {
        cout << "Please enter a pay rate greater than zero\n";
        cin >> payPerHour;
    }
    if(totalHours <= 40)
    {
        grossPay = totalHours * payPerHour;
    }
    else if(totalHours  >= 40)
    {
        grossPay = (40 * payPerHour) + (doubleTime * 2 * payPerHour);
    }
    
    federalTaxes = grossPay * 0.2;
    stateTaxes = grossPay * 0.05;
    netPay = grossPay - federalTaxes - stateTaxes;
    
    system("cls");
    
    if(totalHours <= 40)
    {
    cout << "Hello " << firstName << " " << lastName <<"\n";
    cout << "Employee ID#" << employeeID <<"\n";
    cout << "Your gross pay is $" << grossPay <<"\n";
    cout << "Your regular pay is $" << grossPay <<"\n";
    cout << "Federal taxes with held is $" << federalTaxes <<"\n";
    cout << "State taxes with held is $" << stateTaxes <<"\n"; 
    cout << "Your net pay is $" << netPay <<"\n";
    }
    else if(totalHours > 40)
    {
    cout << "Hello " << firstName << " " << lastName <<"\n";
    cout << "Employee ID# " << employeeID <<"\n";
    cout << "Your gross pay is $" << grossPay <<"\n";
    cout << "Your regular pay is $" << 40 * payPerHour <<"\n";
    cout << "Your overtime pay is $" << doubleTime * 2 * payPerHour <<"\n";
    cout << "Federal taxes with held is $" << federalTaxes <<"\n";
    cout << "State taxes with held is $" << stateTaxes <<"\n"; 
    cout << "Your net pay is $" << netPay <<"\n";
    }
    system("PAUSE");
    return EXIT_SUCCESS;
}

Solved, have the doubleTime variable declared too early, thanks everyone
Topic archived. No new replies allowed.