Weekly Salary Program

Hey guys, you all have helped me loads in the past and I've been appreciative of it all. Before I post here, I try to work out as much as possible rather than posting a small piece of code and then asking for help. This program should be extremely simple to do. Unfortunately I can't think of the exact math on it. I definitely shouldn't be taking a programming class if I'm not good at math, but sometimes I'm able to get by haha! Anyway, I was wondering if there was a better way to write this program as well as if you could give me advice on the math that's involved in the conditional statements. I've got the rough idea of how the program works, but it could definitely use some polishing. My C++ skills are rather lacking to say the least, but I'm definitely trying! Any help, would be greatly appreciated it.

------------ Weekly Salary Program ------------------------------

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
#include <iostream>
#include <string>
using namespace std;

int main()
{
    // Declared Variables Block
    string first, last;
    int hours;
    int minutes;
    float hourly_wage;
    double computed_pay;
    
    // Input Statements Block
    cout << "Enter the Employee's first and last name (ie. Roger Smith): "; 
    cin >> first >>  last;
    cout << "Enter Hours worked: ";
    cin >> hours;
    cout << "Enter Minutes worked: ";
    cin >> minutes;
    cout << "Enter hourly wage: ";
    cin >> hourly_wage;
    
    
    // Output Statements Block
    cout << "\n";
    cout << "---------- Employee Information -----------" << endl;
    cout << "Employee: " << first << " " << last << endl;
    cout << "Time worked: " << hours << "hours"
         << ", " << minutes << " minutes" << endl;
    cout << "Hourly wage: " << hourly_wage << endl;
    cout << "\n";
    
    // Conditional Statement Block
    if (hours > 40)
       {
              computed_pay = hourly_wage * hours * 1.5;
              cout << "The computed pay is: " << computed_pay;
              cout << "\n";
       }
    else if (hours <= 40)
         {
                computed_pay = hourly_wage * hours;
                cout << "The computed pay is: " << computed_pay;
                cout << "\n";
         }
    system ("pause");
    return 0;
}
closed account (3CXz8vqX)
Um.... if you work over 40 hours... you're paid time and and a half for all the hours you have worked? Surely it should only be for the hours you have worked after 40?

If hours over 40 then get difference between 40 and hours worked put into 'overtime worked' variable.
calculate wages for 40 hours as normal. store in varX
hourly_wage * overtime_worked * 1.5. add product to varX
Haha! Stupid me! That's one thing that I'm missing on there. Are there any other tricks that I could add to this program? Other than the mistake on the math.
If anyone is still viewing this and scratching their head, I did manage to get the math right for the overtime. Unfortunately I don't have the right math for the minutes. I need to be able to calculate both the hours and minutes into this program, otherwise the program will not work properly. Since the person worked 39 hours and 30 minutes, the hourly wage should be divided in half since he's getting paid for half the hour, but what if it was 15 minutes or 20 minutes or so on? I'm trying to figure out how to code that part in. That should be the easy part. The hard part is when I need to round it to the cent. For example, if the answer is 421.265, the rounded part should be 421.27.. Here's the current code that I've got thus far.

-------------- Weekly Salary Program ----------------------------

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
#include <iostream>
#include <string>
using namespace std;

int main()
{
    // Declared Variables Block
    string first, last;
    double hours;
    double minutes;
    float hourly_wage;
    float computed_pay;
    float overtime_pay;
    double max_hours = 40;
    
    // Input Statements Block
    cout << "Enter the Employee's first and last name (ie. Roger Smith): "; 
    cin >> first >>  last;
    cout << "Enter Hours worked: ";
    cin >> hours;
    cout << "Enter Minutes worked: ";
    cin >> minutes;
    cout << "Enter hourly wage: ";
    cin >> hourly_wage;
    
    
    // Output Statements Block
    cout << "\n";
    cout << "---------- Employee Information -----------" << endl;
    cout << "Employee: " << first << " " << last << endl;
    cout << "Time worked: " << hours << "hours"
         << ", " << minutes << " minutes" << endl;
    cout << "Hourly wage: " << hourly_wage << endl;
    cout << "\n";
    
    // Conditional Statement Block
    if (hours > 40)
       {
              overtime_pay = (hours - 40) * 1.5 * hourly_wage;
              computed_pay = max_hours * hourly_wage + overtime_pay;
              cout << "The computed pay is: " << computed_pay;
              cout << "\n";
       }
    else if (hours <= 40)
         {
                computed_pay = hourly_wage * hours;
                cout << "The computed pay is: " << computed_pay;
                cout << "\n";
         }
    system ("pause");
    return 0;
}
Topic archived. No new replies allowed.