#include <cstdlib>
#include <iostream>
/* Program to accept the salaries of 10 employees from the user and display them
in descending order for all employees. If the user enters zero, the program
should display the message "The amount should be greater than zero" and accept
the value again */
usingnamespace std;
class empsal
{
float salary[10];
int count;
public:
void input() //method for getting values
{
for (count = 0; count < 10; count++)
{
szeros:
cout << "Salary: ";
cin >> salary[count];
if (salary[count] == 0)
{
cout << endl << "The amount should be greater than zero" << endl;
goto szeros;
}
}
}
void sorting() //method for sorting values
{
cout << endl;
cout << "Salaries displayed in a descending order:: \a\a\a";
cout << endl;
int c, t;
int swapper;
for(c = 0; c < 10; c++) //Bubble array sorting
{
for (t=0; t < 9; t++)
{
if (salary[t+1] > salary[t])
{
swapper = salary[t];
salary[t] = salary[t+1];
salary[t+1] = swapper;
}
}
}
}
void display() //method for displaying values
{
for (count = 0; count < 10; count++)
{
cout << endl << " " << count + 1 << ". " << salary[count] << endl;
}
cout << endl;
}
};
int main(int argc, char *argv[])
{
cout << "******************************SALARIES***********************************" << "\n\n\a";
empsal es;
es.input();
es.sorting();
es.display();
system("PAUSE");
return EXIT_SUCCESS;
}
Feel free to give your opinion... I am open to anything that works!!!