Taxrate Payroll Program(Help Finding Error)

Pages: 12
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
#include <iostream>
#include <fstream>
using namespace std;
int main () {
    ifstream input;// Declare file streams.
    input.open("employee.txt"); //Open the input file
        int numberofemployees;
        int employeeid, hoursworked;
        float hourlyrate, grosspay, taxamount, netpay;
        float const TAXRATE=0.20;
        numberofemployees=0;
        while(input>>employeeid>>hoursworked>>hourlyrate) {
        grosspay=hoursworked*hourlyrate;
        if( grosspay > 1000 )    TAXRATE=0.30;
              else if( grosspay > 800 ) TAXRATE=0.20;
              else if( grosspay > 500 ) TAXRATE=0.10;
              else TAXRATE = 0.0;
        taxamount=grosspay*TAXRATE;
        netpay=grosspay-taxamount;
        cout<<"EMPLOYEE ID IS " << employeeid<<endl;
        cout<<"THE HOURS WORKED ARE " << hoursworked<<endl;
        cout<<"THE HOURLY RATE IS " << hourlyrate<<endl;
        cout<<"THE GROSSPAY IS " << grosspay<<endl;
        cout<<"THE TAXAMOUNT IS " << taxamount<<endl;
        cout<<"THE NETPAY IS " << netpay<<endl<<endl;
        }//WHILE
        input.close();//Close the files
    system ( "pause" );
}//main() 


Can't seem to find my error. Any suggestions?
what does it do and what doesn't ?
any errors?
AT line 10,
 
float const TAXRATE=0.20


AT line 14,
 
TAXRATE=0.30


You are contradicting yourself.

when something is constant, it is not supposed to be changed!
The employee.txt input's an employees id, hourly rate and hours worked. I needed to change tax rates depending on their salary and I can't get the program to execute. It has something to do with line 14. Can't seem to figure it out
Depends on your platform and IDE,

line 28

 
system("PAUSE");
Oh of course. So does line 10 just become float TAXRATE=0.20?
Yup. There is no need for it to be constant right? =)
Can you print out the error message?
Got it to work thanks dude! Now I just need to declare a Martial Status by adding 5% to single person and deducting 5% to a head of household,
Declare marital status as a character: S=Single M=Married H=Head of Household is what I need to do.

My buddy gave me this hint:
char ms; if (ms=='s') taxrate=taxrate+0.05;
else if (........)

Where do you think the best place to put that staement is?
Actually anywhere you like, since it is addition, not multiplication.
It would be more elegant if you use a switch statement:

1
2
3
4
5
6
7
8
switch(ms)
{
   case 'S': taxrate+=0.05;
   break;
   case 'M': taxrate+=0.10;
   break;
   default: taxrate+=0.20;
}
Now my question is because I've never used switch really. Between which lines am I inputting this statement? I'm gonna try inputting it in the right place till I get a reply back buddy
Also because it is a symbol do i put char S, M; up at the top?
nope.

it should be stored in the employee.txt like the hourly rate, worked hours, etc.

and

it should be read from the file.

I'm sorry for all of the questions but I'm totally new to programming.
2 Questions:

Here's my employee.txt:


8572 40 12.00
6423 40 15.00
7465 40 10.00
2477 40 16.00
5996 40 18.00

Where do I put it?

Also the statement:
1
2
3
4
5
6
7
8
switch(ms)
{
   case 'S': taxrate+=0.05;
   break;
   case 'M': taxrate+=0.10;
   break;
   default: taxrate+=0.20;
}


Goes exactly where? Then I should be good
employee.txt

8572 40 12.00 M
6423 40 15.00 S
...

I suggest that you put it right after the line 17 before you compute the taxamount.

=)
Ok let me try that I'll get back to ya
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
#include <iostream>
#include <fstream>
using namespace std;
int main () {
    ifstream input;// Declare file streams.
    input.open("employee.txt"); //Open the input file
        int numberofemployees;
        int employeeid, hoursworked;
        float hourlyrate, grosspay, taxamount, netpay;
        float TAXRATE=0.20;
        numberofemployees=0;
        while(input>>employeeid>>hoursworked>>hourlyrate) {
        grosspay=hoursworked*hourlyrate;
        if( grosspay > 1000 )    TAXRATE=0.30;
              else if( grosspay > 800 ) TAXRATE=0.20;
              else if( grosspay > 500 ) TAXRATE=0.10;
              else TAXRATE = 0.0;
              switch(ms)
{
   case 'S': taxrate+=0.05;
   break;
   case 'M': taxrate+=0.10;
   break;
   default: taxrate+=0.20;
}
        taxamount=grosspay*TAXRATE;
        netpay=grosspay-taxamount;
        cout<<"EMPLOYEE ID IS " << employeeid<<endl;
        cout<<"THE HOURS WORKED ARE " << hoursworked<<endl;
        cout<<"THE HOURLY RATE IS " << hourlyrate<<endl;
        cout<<"THE GROSSPAY IS " << grosspay<<endl;
        cout<<"THE TAXAMOUNT IS " << taxamount<<endl;
        cout<<"THE NETPAY IS " << netpay<<endl<<endl;
        }//WHILE
        input.close();//Close the files
    system ( "pause" );
}//main() 


That's what I have.

8572 40 12.00 M
6423 40 15.00 S
7465 40 10.00 M
2477 40 16.00 S
5996 40 18.00 M

That's what I have and it's not executing. Did I do something wrong?

It states MS is undeclared
Pages: 12