Assignment Problems

I appreciate any comments I can get on what I did wrong. Here are the errors I get when I compile:

assignment3.cc: In function `int main()':
assignment3.cc:57: error: expected `;' before '{' token
assignment3.cc:113: error: expected `;' before '{' token

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <iostream>
#include <string>
using namespace std;

int main()
{
        const double high_wage = 15.00;
        const double low_wage = 7.70;
        const double Fed_tax = .25;
        const double Oh_tax = .05;
        const int Max_count = 3;
        const int full_time = 40;
        string two_name, two_address, two_zip, three_name, three_address, three_zip, four_name, four_address, four_zip;
        double emp_ID, hrs_worked, wage_hourly, ot_hrs; totalO_hrs,taxable_amount, Fed_tax_to, OH_tax_to, total_pay;
        int count;

      while (count <= 4)
        {
                 
                 cout << "\n Enter ID number ";
                 cin >> emp_ID;
                 if (emp_ID == 1122)
                        {
                        if ((emp_ID == 1133) ||  (emp_ID == 1144))
                        break;
                        }
                else
                {
                 cout << "\n An invalid ID was just entered";
                 cout << "\nPlease check the ID number and re-enter ";
                 count++;
                }
                }
        
          if (emp_ID == 1122)
                {
                cout <<"Enter full name: ";
                getline (cin, two_name);

                cout <<"Enter address:";
                getline (cin, two_address);

        cout <<"Enter zip code:  ";
                getline (cin, two_zip);
                }
        else if (emp_ID == 1133)
                {
                cout <<"Enter full name: ";
                getline (cin, three_name);
                 
                cout <<"Enter address: ";
                getline (cin, three_address);
            
                cout <<"Enter zip code: ";
                getline (cin, three_zip);
                }
        else (emp_ID == 1144)
                {
                cout <<"Enter full name: ";
                getline (cin, four_name);
                 
                cout <<"Enter address: ";
                getline (cin, four_address);
                
                cout <<"Enter zip code: ";
                getline (cin, four_zip);
                }

            cout << "\nEnter number of hours worked: ";
            cin >> hrs_worked;
                 
            if (hrs_worked > full_time)
                {
                ot_hrs = hrs_worked-full_time;
                totalO_hrs = ot_hrs + (ot_hrs/2) + full_time;
                cout <<"\nTotal hours with overtime hours: ";
                cout<<totalO_hrs;  
                }
        cout<<"\nEnter hourly wage: ";
        cin>> wage_hourly;
            
        if (wage_hourly > 15.00)
        {        
                if (hrs_worked > full_time)

                taxable_amount = wage_hourly * totalO_hrs - 2.00;
                
        }
        else if (wage_hourly > 15.00)
        {
                if (hrs_worked <= full_time)
            
                taxable_amount = wage_hourly * hrs_worked - 2.00;
                
                }
        else if (wage_hourly < 7.70)  
                {
                if (hrs_worked > full_time)
                taxable_amount = wage_hourly * totalO_hrs + 15.00;
        }        
        else if (wage_hourly < 7.70)
        {       
                if (hrs_worked <= full_time)
                taxable_amount = wage_hourly * hrs_worked + 15.00;
        }
                
        else if (wage_hourly >= 7.70)
        {
                if ((wage_hourly <=15.00) && (hrs_worked > full_time))
                taxable_amount = wage_hourly * totalO_hrs;
        }
                 
        else (wage_hourly >= 7.70)
        {
                if ((wage_hourly <= 15.00) && (hrs_worked <= full_time))
                taxable_amount = wage_hourly * hrs_worked;

        }
        cout<<"\nYour taxable amount: ";
        cout<<taxable_amount;
                
        Fed_tax_to = taxable_amount * Fed_tax ;
        OH_tax_to = taxable_amount * Oh_tax ;
        total_pay = taxable_amount - Fed_tax_to - OH_tax_to ;
         
        cout<<"\nEmployee ID: " <<emp_ID;
        cout<<"\nPay before taxes: " <<taxable_amount;
        cout<<"\nPay after taxes: " <<total_pay;

return 0;
}
Last edited on
I don't know what may cause that error here. Btw in your program you wrote "#include<iostream>" or "include<iostream>"? I don't think you made that mistake but I was just asking : )
First issue: Please put your code in /code brackets. It's the <> button to the right of the message window.

Second issue: Please format your code with tabs to make it easier to read. Having all brackets and text all the way to the left makes it very annoying to read through.

Third issue: You'll need to do some reading about how to construct for loops.
for (emp_ID == 1122; emp_ID == 1133; emp_ID == 1144)
is not a valid for loop.

http://www.cplusplus.com/doc/tutorial/control/

I stopped there for now. Please fix this stuff and I'd be more than happy to continue reading through it. :)

Thanks!
Thanks for the comments.

I made some changes and had different compiler errors that are in the original post. Any more comments I can get would be greatly appreciated.

I still have some work to do on it but I want to get this part fixed. I have to display user id and their address, zip, and name incase you are wondering why I was declaring the strings. Thanks again.
Last edited on
I need to go to class myself now, but the first thing I see is:

1
2
3
4
5
6
       do   // <--- This is making the next two statements be called at LEAST once... you don't want this!  This should be a plain while statement.
            {
                 cout << "\n An invalid ID was just entered";
                 cout << "\nPlease check the ID number and reenter";
            }while ((emp_ID != 1122) &&  (emp_ID != 1133) &&  (emp_ID !=1144));
            } // <--- orphaned bracket. Needs deleting! (Line 24) 


Last edited on
I updated my code in the original post and I almost got it. Im having a hard time finding these last couple errors. Thanks again for the help.
thanks for the help, i finally got it to work. I am having one more problem though. It is skipping over when I want to input name and going straight to address. Why would it do that? Any help would be appreciated. Thanks again.
Couple issues:

Line 14: double emp_ID, hrs_worked, wage_hourly, ot_hrs; totalO_hrs,taxable_amount, Fed_tax_to, OH_tax_to, total_pay;

There's a semi-colon in the middle of your variable declarations.

Line 57: else (emp_ID == 1144)

else statements do not have any arguments after them. They're there to say "everything else", meaning there are no stipulations. If you want this to have an argument, it needs to be else if.

You first while statement is only going to work when count is less than 4. If you don't give count an initial value, it's going to pick up a random one and you'll probably skip the while statement entirely 99.9% of the time. You have also created an endless loop as long as the employee ID is 1122, as the while loop has no way to break out if this is true... and, I'm not quite sure why you nested another if statement within that one on line 24 as it's completely impossible for that statement to ever be true. The second if statement will only be checked if emp_ID is 1122, but the code under the if statement will only happen if emp_ID is 1133 or 1144... which is impossible if it's set to 1122. So yeah, you have your work cut out for you.

Try practicing reading your code out loud, and walk yourself through what your code will be doing in very simple steps. For 'if' statements, ask yourself what will happen when something ISN'T true. Ask yourself things like, "Is that what I want it to do?". Imagine actually putting the data into the console, and imagine what will happen with different values. If you can't imagine it like that, use cout statements to verify that a certain piece of code has ran and run the program (even if you have to create a test.cpp file and just put bits of your code into it to test each part).

Also, you'll need to use the command cin.ignore(1000,'\n'); after cin >> emp_ID;. Your getline statement is recognizing the new line statement at the end of your employee ID and taking that as it's input. the cin.ignore statement will essentially tell the system to ignore everything after the value input of 1122.

Oh, and you need to completely revisit your book on if/else if/else statements. Your hourly wage section is not kosher at all. You should never have an else if statement that runs off the exact same argument as another one in the same string of if else statements. Simply place whatever code you were going to put in the second one under the first else if statement. For example:

1
2
3
4
5
6
7
8
9
10
        else if (wage_hourly < 7.70)
                {
                if (hrs_worked > full_time)
                taxable_amount = wage_hourly * totalO_hrs + 15.00;
        }
        else if (wage_hourly < 7.70)
        {
                if (hrs_worked <= full_time)
                taxable_amount = wage_hourly * hrs_worked + 15.00;
        }


can be condensed into:

1
2
3
4
5
6
7
        else if (wage_hourly < 7.70)
        {
                if (hrs_worked > full_time)
                taxable_amount = wage_hourly * totalO_hrs + 15.00;
                else
                taxable_amount = wage_hourly * hrs_worked + 15.00;
        }


although even that is not going to be mathematically correct. Can you explain your math for not only calculating the taxable amount (what does the 15.00 represent?), but also how you calculate the totalO_hrs? It makes no sense to me at all.
Thank you so much Kazekan. I greatly appreciate the help.. I fixed all the issues you suggested and it runs correctly. The 15.00 was a part of the original question. The total_O hrs was overtime hours plus overtime/2, as well as plus full time (40) hours. Im not sure if it is correct or not but I always thought that overtime was time and a half. If I am wrong, I would appreciate the correct formula for determining the number of hours for over time. Thanks again.
Fantastic! I'm glad to hear that helped. :)

Overtime hours are paid at overtime wages, which are typically "time and a half" (which is actually a way of saying "at 1.5x your normal wage"). Sometimes overtime is paid at double pay, but we'll leave that out of the equation. :) So, if someone were to work 42 hours and they're normally paid $20/hour, they would get paid $20/hour for 40 hours, and $30/hour for the extra 2 hours they worked. This would therefore total $860 even.

Also, I'm not sure how detailed you need to be on how much they get taxed, but typically overtime is taxed higher than regular time. :)

Hope that helps!

Happy coding.
Topic archived. No new replies allowed.