problem in my assignment


my program does not arrange Salaries well when the //bubbl sort
And gives me an error when calculating the salary tax when the // calc 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include<iostream.h>
#include <vector>
#include <stdio.h>                          //ahmed.ha.hnd
#include<conio.h>



struct employee
{
char name[20];
 float  salary;
int birthday;
char sex [10];

};
void main()
{
	
 employee emp[100];

{
	int n;

	cout << "A program for collecting employee information";
	cout << endl;
	cout << "And displaying the collected information";
	cout << endl << endl;
	cout << "How many employees:";
	cin >> n;
	cout << endl;


	cout << "Enter the following information:"<<endl;
	cout << endl;

for (int i=0; i<n; i++){
		cout << "Enter information for employee no: " << i;
		cout << endl;


cout<<"Enter the Employee name :" ;cin>>emp[i].name;
cout<<"Enter the salary :";cin>>emp[i].salary;
cout<<"Enter the birthday :";cin>>emp[i].birthday ;
cout<<"Enter the sex :";cin>>emp[i].sex;
cout<<endl;
}


void bubb(employee emp,int n);       //bubble sort
{
employee temp;
for(int j=0;j<n;j++)
{
if(emp[j].salary<emp[j+1].salary)
{
for(int i=j;i<n-1;i++)
{
temp=emp[i];
emp[i]=emp[i+1];
emp[i+1]=temp;
}
}
}


	cout << "Employee entered information:"<< endl;
	cout << "============================" << endl;
	cout << "Name  salary birthday   Sex	" << endl;
for( i=0;i<n;i++)
{
    	cout << emp[i].name		<< "\t";
		cout << emp[i].salary << "\t";
		cout << emp[i].birthday; cout	<< "\t";
		cout << emp[i].sex    ;
		cout << 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;
}
cout<<endl;
cout << "Total Salary: "   << total_salary <<endl;
cout << "============"<<endl;
cout << "Highest Salary: " << highest_salary << endl;
cout << "=============="<<endl;



void main();      //calc tax

 float tax=0;      
 float salary=0;

if (emp[i].salary<=1999)
{
tax=(emp[i].salary*5)/100;
}

 else if (emp[i].salary<=2999)
{
tax=(emp[i].salary*7.5)/100;

	 }

else if (emp[i].salary<=3999)
	 {
tax=(emp[i].salary*10)/100;
	 }


else  if (emp[i].salary>4000)
	 {

tax=(emp[i].salary*15)/100;
	 }


salary=emp[i].salary-tax;



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

}
}



/*out put my prgram:


How many employees:5

Enter the following information:

Enter information for employee no: 0
Enter the Employee name :ahahd
Enter the salary :15000
Enter the birthday :1987
Enter the sex :m

Enter information for employee no: 1
Enter the Employee name :asnb
Enter the salary :12000
Enter the birthday :1956
Enter the sex :m

Enter information for employee no: 2
Enter the Employee name :asmar
Enter the salary :14000
Enter the birthday :1965
Enter the sex :f

Enter information for employee no: 3
Enter the Employee name :sara
Enter the salary :25000
Enter the birthday :1960
Enter the sex :f

Enter information for employee no: 4
Enter the Employee name :nera
Enter the salary :2000
Enter the birthday :1980
Enter the sex :f

Employee entered information:
============================
Name  salary birthday   Sex         //does not arrange Salaries well
ahahd   15000   1987    m
asmar   14000   1965    f
sara    25000   1960    f
asnb    12000   1956    m
nera    2000    1980    f

Total Salary: 68000
============
Highest Salary: 25000
==============
Salary after tax :  Employee Name :
================    =============
-1.02005e+008                   ahahd
-1.02005e+008                   asmar        //gives me an error when
                                            //calculating the salary tax
-1.02005e+008                   sara
-1.02005e+008                   asnb
-1.02005e+008                   nera
Press any key to continue*/






Last edited on
The program does not compile:
http://ideone.com/CVWvVg
When I fixed the include statements:
http://ideone.com/euOnEb
Thank you
Is there any advice for me to correct mistakes
Get a compiler from within the last ten years and you should be fine.
Sorry I did not become good in the language c++
Can you tell me more about my program to become without erorr


can you help me?
Last edited on
I fixed more errors for you and fixed the indentation so you can more clearly see what is wrong:

http://ideone.com/rIEibM
thank you
when i use // std::cin >> n;
std::cout << std::endl;
or Using Namespace Std , Was correct all the mistakes, but the problem still
when the bubble sort and calc tax


output

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
A program for collecting employee information
And displaying the collected information

How many employees:5

Enter the following information:

Enter information for employee no: 0
Enter the Employee name :asas
Enter the salary :5000
Enter the birthday :1988
Enter the sex :m

Enter information for employee no: 1
Enter the Employee name :adre
Enter the salary :10000
Enter the birthday :1965
Enter the sex :m

Enter information for employee no: 2
Enter the Employee name :jhiu
Enter the salary :8000
Enter the birthday :198
Enter the sex :f

Enter information for employee no: 3
Enter the Employee name :iuyrt
Enter the salary :11000
Enter the birthday :1965
Enter the sex :m

Enter information for employee no: 4
Enter the Employee name :poiu
Enter the salary :6000
Enter the birthday :1945
Enter the sex :f

Employee entered information:
============================
Name  salary birthday   Sex
adre    10000   1965    m
iuyrt   11000   1965    m
poiu    6000    1945    f              //Not well arrange Salaries
jhiu    8000    198     f
asas    5000    1988    m

Total Salary: 40000
============
Highest Salary: 11000
==============
Salary after tax :  Employee Name :
================    =============
-1.02005e+008                   adre
-1.02005e+008                   iuyrt
-1.02005e+008                   poiu       //Does not give me the 
                                                         //values ​​of salaries after tax
-1.02005e+008                   jhiu
-1.02005e+008                   asas
Press any key to continue
I fixed more errors for you:
http://ideone.com/KYOL8t
Lines 90-108 need to be in a for loop.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
   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;
            }
When I put the number one works well



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
And displaying the collected informat

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
Last edited on
here not work


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
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
Topic archived. No new replies allowed.