Structures

Declare a structure Employee. An employee has a name, and employee number and salary.
Write a function that takes a employee as parameter and prints out the details of that
employee. The details of the employees are contained in the file called employees.txt in the
following format:
employee1 9007 35000
employee2 9005 45000
employee3 9003 45000.
The total number of employees is not known.
Finally write the main function that reads the data from the file and print out the details of all
employees earning more than 300000.


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>
using namespace std;

double taxPayable(double salary);
double tax;
{if(salary <= 150000)
tax = salary*0.2;
else
tax = 30000 + (salary - 150000)*0.25;
return (tax);
}

int main()
{
      double amount;
	  cout<<"Enter the amount of your salary:  " ;
	  cin>>amount;
	  cout<<endl;
	   do{
		  cout<<"The value your tax is:  ";
		  cout<<taxPayable(amount)<<endl;
		  cout<<"Enter the amount of your salary:  " ;
	  cin>>amount;

}while (amount!=0 && amount>0);

    return 0;
}


it gives me 1 error dnt knw whaats wrong!
Your definition of function taxPayable has several errors, including the semicolon on the first line, and misplaced opening brace.

1
2
3
4
5
6
7
8
double taxPayable(double salary);
double tax;
{if(salary <= 150000)
tax = salary*0.2;
else
tax = 30000 + (salary - 150000)*0.25;
return (tax);
}

replace with:
1
2
3
4
5
6
7
8
9
10
11
double taxPayable(double salary)
{
    double tax;

    if (salary <= 150000)
        tax = salary*0.2;
    else
        tax = 30000 + (salary - 150000)*0.25;

    return (tax);
}


This line doesn't really need both conditions:
while (amount!=0 && amount>0);

This is simpler: while (amount > 0);
Topic archived. No new replies allowed.