Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAX_PERSON 5
- struct person {
- char name[256];
- char surname[256];
- int hours;
- float rate;
- int bonus;
- };
- float calcSalary(struct person *firstPerson);
- void printSalary(struct person *firstPerson);
- void highestPaid(struct person *firstPerson);
- int main() {
- struct person persons[MAX_PERSON];
- int n = 5, i;
- for (i=0; i<n; i++) {
- printf("Please enter the name and surname of the person #%d: ", i+1);
- scanf("%s %s", persons[i].name, persons[i].surname);
- printf("Please enter the number of hours worked by the person #%d: ", i+1);
- scanf("%d", &persons[i].hours);
- printf("Please enter the hourly rate of the person #%d: ", i+1);
- scanf("%f", &persons[i].rate);
- printf("Please enter the bonus rate of the person #%d (in percent): ", i+1);
- scanf("%d", &persons[i].bonus);
- }
- float totalSalary = calcSalary(persons);
- printf("Total salary: %f\n", totalSalary);
- printSalary(persons);
- highestPaid(persons);
- return 0;
- }
- float calcSalary(struct person *firstPerson) {
- float totalSalary = 0.0;
- int i;
- for (i=0; i<MAX_PERSON; i++) {
- totalSalary = totalSalary + (firstPerson[i].hours * firstPerson[i].rate) +
- (firstPerson[i].hours * firstPerson[i].rate * (float)firstPerson[i].bonus / 100);
- }
- return totalSalary;
- }
- void printSalary(struct person *firstPerson) {
- int i;
- for (i=0; i<MAX_PERSON; i++) {
- float salary = (firstPerson[i].hours * firstPerson[i].rate) +
- (firstPerson[i].hours * firstPerson[i].rate * (float)firstPerson[i].bonus / 100);
- printf("%s %s salary is %f\n", firstPerson[i].name, firstPerson[i].surname, salary);
- }
- }
- void highestPaid(struct person *firstPerson) {
- int i;
- float highest = 0.0;
- int highestIndex = 0;
- for (i=0; i<MAX_PERSON; i++) {
- float salary = (firstPerson[i].hours * firstPerson[i].rate) +
- (firstPerson[i].hours * firstPerson[i].rate * (float)firstPerson[i].bonus / 100);
- if (salary > highest) {
- highest = salary;
- highestIndex = i;
- }
- }
- printf("The highest paid person is %s %s\n", firstPerson[highestIndex].name, firstPerson[highestIndex].surname);
- }
Advertisement
Add Comment
Please, Sign In to add comment