anyone have any code to classify Salaries ascending or descending to this program

How do I print Salaries from smallest to largest and print top salary
And calculate the total salaries by this program


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
#include<iostream.h>
struct employee
{
char name[20];
float salary;
int birthday;
char sex [6];

};
void main()
{
struct employee emp[25];
for(int i=0;i<25;i++)
{
cout<<"Enter the Employee name :"<<endl;
cin>>emp[i].name;
cout<<"Enter the salary :"<<endl;
cin>>emp[i].salary;
cout<<"Enter the birthday :"<<endl;
cin>>emp[i].birthday;
cout<<"Enter the sex :"<<endl;
cin>>emp[i].sex;
}
for(i=0;i<25;i++)
cout<<" the name is:"  << emp[i].name<<" , "<<"salary is: "<<emp[i].salary<<" , " <<
"the birthday is:" <<emp[i].birthday<<" , "<<" the sex is:"<<emp[i].sex<<endl;
}
Last edited on
bubble sort get some temporary variable and from the a[i] every time check if its smaller than a next one. (bad english heres the example)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
do
{
             z=0;
             {      for(i=0;i<25;i++)
                     {
                              if(a[i]<a[i+1])
                               {
                                  temporary=a[i];
                                  a[i]=a[i+1];
                                  a[i+1]=temporary;
                                  z=1;
                               }
                      }
               }
}
while(z==1);

later you add birhtday name and sex...
I do not know how I apply this example

Can anyone help me
Last edited on
1
2
3
4
5
6
7
8
9
10
11
float highest_salary = 0.0f;
float total_salary = 0.0;
for (unsigned i = 0; i < 25; ++i) {
 if (emp[i].salary > highest_salary);
   highest_salary = emp[i].salary;

 total_salary += emp[i].salary;
}

cout << "Total Salary: " << total_salary << endl;
cout << "Highest Salary: " << highest_salary << endl;


That should help :)
thank you for help me

it gooooooooooood
Does anyone have any code to classify Salaries ascending or descending to this program
Topic archived. No new replies allowed.