proplem in loops/tax

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
#include<iostream>
#include <vector>
 
struct employee
{                                              //ahmed.ha.hnd
    char name[20];
    float  salary;
    int birthday;
    char sex [10];
};
 
int main()
{
    employee emp[100];
 
    {
        int n;
    
        std::cout << "A program for collecting employee information";
        std::cout << std::endl;
        std::cout << "And displaying the collected information";
        std::cout << std::endl << std::endl;
        std::cout << "How many employees:";
        std::cin >> n;
        std::cout << std::endl;
 
        std::cout << "Enter the following information:"<<std::endl;
        std::cout << std::endl;
    
        for(int i=0; i<n; i++)
        {
            std::cout << "Enter information for employee no: " << i;
            std::cout << std::endl;
    
            std::cout<<"Enter the Employee name :" ;std::cin>>emp[i].name;
            std::cout<<"Enter the salary :";std::cin>>emp[i].salary;
            std::cout<<"Enter the birthday :";std::cin>>emp[i].birthday ;
            std::cout<<"Enter the sex :";std::cin>>emp[i].sex;
            std::cout<<std::endl;
        }
 
        {
            employee temp;
            for(int i = 0; i < n; i++)
            {
                for(int j = i+1; j < n; j++)
                {
                    if(emp[i].salary<emp[j].salary)
                    {
                        temp=emp[i];
                        emp[i]=emp[j];
                        emp[j]=temp;
                    }
                }
            }
 
                std::cout << "Employee entered information:"<< std::endl;
                std::cout << "============================" << std::endl;
                std::cout << "Name  salary birthday   Sex       " << std::endl;
 
            for(i = 0; i < n; i++)
            {
                        std::cout << emp[i].name                << "\t";
                        std::cout << emp[i].salary << "\t";
                        std::cout << emp[i].birthday; std::cout << "\t";
                        std::cout << emp[i].sex    ;
                        std::cout << std::endl;
            
            }
 
            int highest_salary=0; 
            int total_salary=0; 
            for(i = 0; i < n; i++)
            {
                if(emp[i].salary > highest_salary)
                {
                    highest_salary = emp[i].salary;
                }
                total_salary += emp[i].salary;
            }
            std::cout<<std::endl;
            std::cout << "Total Salary: "   << total_salary <<std::endl;
            std::cout << "============"<<std::endl;
            std::cout << "Highest Salary: " << highest_salary << std::endl;
            std::cout << "=============="<<std::endl;
    
            float tax=0;      
            float salary=0;
for(i = 0; i < n; i++)

            if(emp[i].salary <= 1999)
            {
                tax = (emp[i].salary*5)/100.0;
            }
            else if (emp[i].salary<=2999)
            {
                tax=(emp[i].salary*7.5)/100.0;
            }
    
            else if (emp[i].salary<=3999)
            {
                tax=(emp[i].salary*10)/100.0;
            }
            else  if (emp[i].salary>4000)
            {
                tax=(emp[i].salary*15)/100.0;
            }
 

            salary=emp[i].salary-tax;
 
            std::cout<<"Salary after tax :"<<"  Employee Name :   "<<std::endl;
            std::cout<<"================ " <<"   ============="<<std::endl;
            for(i = 0; i < n; i++)
            std::cout << salary <<"                   "  <<  emp[i].name << std::endl;                    
        }
    }
return 0;
}


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
When I put the number one works well
/*

How many employees:1

Enter the following information:

Enter information for employee no: 0
Enter the Employee name :assd
Enter the salary :15000
Enter the birthday :1987
Enter the sex :5

Employee entered information:
============================
Name  salary birthday   Sex
assd    15000   1987    5

Total Salary: 15000
============
Highest Salary: 15000
==============
Salary after tax :  Employee Name :
================    =============
12750                   assd
Press any key to continue*/


But when I go in more than one number appears the problem of repetition without counting salaries after tax

/*A program for collecting employee informat
And displaying the collected information

How many employees:3

Enter the following information:

Enter information for employee no: 0
Enter the Employee name :asdd
Enter the salary :1000
Enter the birthday :198
Enter the sex :m

Enter information for employee no: 1
Enter the Employee name :dsre
Enter the salary :2000
Enter the birthday :1965
Enter the sex :m

Enter information for employee no: 2
Enter the Employee name :hguyt
Enter the salary :3000
Enter the birthday :1659
Enter the sex :m

Employee entered information:
============================
Name  salary birthday   Sex
hguyt   3000    1659    m
dsre    2000    1965    m
asdd    1000    198     m

Total Salary: 6000
============
Highest Salary: 3000
==============
Salary after tax :  Employee Name :
================    =============
2700                   hguyt
2700                   dsre
2700                   asdd
Press any key to continue

*/
Last edited on
and output this

1
2
3
4
5
6
7
Salary after tax
================
-1.02005e+008
-1.02005e+008
-1.02005e+008
-1.02005e+008
-1.02005e+008
Missing curly brackets for the for loop beginning on line 89.
Same the error

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
#include<iostream>          //ahmed.ha.hnd
#include <vector>
 
struct employee
{
    char name[20];
    float  salary;
    int birthday;
    char sex [10];
};
 
int main()
{
    employee emp[100];
 
    {
        int n;
    
        std::cout << "A program for collecting employee information";
        std::cout << std::endl;
        std::cout << "And displaying the collected information";
        std::cout << std::endl << std::endl;
        std::cout << "How many employees:";
        std::cin >> n;
        std::cout << std::endl;
 
        std::cout << "Enter the following information:"<<std::endl;
        std::cout << std::endl;
    
        for(int i=0; i<n; i++)
        {
            std::cout << "Enter information for employee no: " << i;
            std::cout << std::endl;
    
            std::cout<<"Enter the Employee name :" ;std::cin>>emp[i].name;
            std::cout<<"Enter the salary :";std::cin>>emp[i].salary;
            std::cout<<"Enter the birthday :";std::cin>>emp[i].birthday ;
            std::cout<<"Enter the sex :";std::cin>>emp[i].sex;
            std::cout<<std::endl;
        }
 
        {
            employee temp;
            for(int i = 0; i < n; i++)
            {
                for(int j = i+1; j < n; j++)
                {
                    if(emp[i].salary<emp[j].salary)
                    {
                        temp=emp[i];
                        emp[i]=emp[j];
                        emp[j]=temp;
                    }
                }
            }
 
                std::cout << "Employee entered information:"<< std::endl;
                std::cout << "============================" << std::endl;
                std::cout << "Name  salary birthday   Sex       " << std::endl;
 
            for(i = 0; i < n; i++)
            {
                        std::cout << emp[i].name                << "\t";
                        std::cout << emp[i].salary << "\t";
                        std::cout << emp[i].birthday; std::cout << "\t";
                        std::cout << emp[i].sex    ;
                        std::cout << std::endl;
            
            }
 
            int highest_salary=0; 
            int total_salary=0; 
            for(i = 0; i < n; i++)
            {
                if(emp[i].salary > highest_salary)
                {
                    highest_salary = emp[i].salary;
                }
                total_salary += emp[i].salary;
            }
            std::cout<<std::endl;
            std::cout << "Total Salary: "   << total_salary <<std::endl;
            std::cout << "============"<<std::endl;
            std::cout << "Highest Salary: " << highest_salary << std::endl;
            std::cout << "=============="<<std::endl;
    
            float tax=0;      
            float salary=0;
    for(i = 0; i < n; i++)
	{
            if(emp[i].salary <= 1999)
            {
                tax = (emp[i].salary*5)/100.0;
            }
            else if (emp[i].salary<=2999)
            {
                tax=(emp[i].salary*7.5)/100.0;
            }
    
            else if (emp[i].salary<=3999)
            {
                tax=(emp[i].salary*10)/100.0;
            }
            else  if (emp[i].salary>4000)
            {
                tax=(emp[i].salary*15)/100.0;
            }
 
            salary=emp[i].salary-tax;
 
            std::cout<<"Salary after tax :"<<"  Employee Name :   "<<std::endl;
            std::cout<<"================ " <<"   ============="<<std::endl;
            for(i = 0; i < n; i++)
            std::cout << salary <<"                   "  <<  emp[i].name << std::endl;                    
        }
    }
}
}
Last edited on
The closing curly bracket should have been on line 110. Line 109 should be changed to emp[i].salary -= tax;. Line 114 should be changed to std::cout << emp[i].salary << ...;
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
#include<iostream>
#include <vector>
 
struct employee
{                                                 //ahmed.ha.hnd
    char name[20];
    float  salary;
    int birthday;
    char sex [10];
};
 
int main()
{
    employee emp[100];
 
    {
        int n;
    
        std::cout << "A program for collecting employee information";
        std::cout << std::endl;
        std::cout << "And displaying the collected information";
        std::cout << std::endl << std::endl;
        std::cout << "How many employees:";
        std::cin >> n;
        std::cout << std::endl;
 
        std::cout << "Enter the following information:"<<std::endl;
        std::cout << std::endl;
    
        for(int i=0; i<n; i++)
        {
            std::cout << "Enter information for employee no: " << i;
            std::cout << std::endl;
    
            std::cout<<"Enter the Employee name :" ;std::cin>>emp[i].name;
            std::cout<<"Enter the salary :";std::cin>>emp[i].salary;
            std::cout<<"Enter the birthday :";std::cin>>emp[i].birthday ;
            std::cout<<"Enter the sex :";std::cin>>emp[i].sex;
            std::cout<<std::endl;
        }
 
        {
            employee temp;
            for(int i = 0; i < n; i++)
            {
                for(int j = i+1; j < n; j++)
                {
                    if(emp[i].salary<emp[j].salary)
                    {
                        temp=emp[i];
                        emp[i]=emp[j];
                        emp[j]=temp;
                    }
                }
            }
 
                std::cout << "Employee entered information:"<< std::endl;
                std::cout << "============================" << std::endl;
                std::cout << "Name  salary birthday   Sex       " << std::endl;
 
            for(i = 0; i < n; i++)
            {
                        std::cout << emp[i].name                << "\t";
                        std::cout << emp[i].salary << "\t";
                        std::cout << emp[i].birthday; std::cout << "\t";
                        std::cout << emp[i].sex    ;
                        std::cout << std::endl;
            
            }
 
            int highest_salary=0; 
            int total_salary=0; 
            for(i = 0; i < n; i++)
            {
                if(emp[i].salary > highest_salary)
                {
                    highest_salary = emp[i].salary;
                }
                total_salary += emp[i].salary;
            }
            std::cout<<std::endl;
            std::cout << "Total Salary: "   << total_salary <<std::endl;
            std::cout << "============"<<std::endl;
            std::cout << "Highest Salary: " << highest_salary << std::endl;
            std::cout << "=============="<<std::endl;
    
            float tax=0;      
            
    for(i = 0; i < n; i++)
	{
            if(emp[i].salary <= 1999)
            {
                tax = (emp[i].salary*5)/100.0;
            }
            else if (emp[i].salary<=2999)
            {
                tax=(emp[i].salary*7.5)/100.0;
            }
    
            else if (emp[i].salary<=3999)
            {
                tax=(emp[i].salary*10)/100.0;
            }
            else  if (emp[i].salary>4000)
            {
                tax=(emp[i].salary*15)/100.0;
            }
 
            emp[i].salary -= tax;
	}
            std::cout<<"Salary after tax :"<<"  Employee Name :   "<<std::endl;
            std::cout<<"================ " <<"   ============="<<std::endl;
            for(i = 0; i < n; i++)
            std::cout <<  emp[i].salary<<"                   "  <<  emp[i].name << std::endl;                    
        }
    }
}



Is this true?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Employee entered
================
Name  salary bir
5       25000
aa      5000
5       3500
5       3000
5       1000


Salary after tax
================
21250
4250
3150
2700
950
Last edited on
Thanks a lot
I am grateful to you
Topic archived. No new replies allowed.