Vla_DOS

2

Jan 28th, 2023
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.24 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define MAX_PERSON 5
  6.  
  7. struct person {
  8.   char name[256];
  9.   char surname[256];
  10.   int hours;
  11.   float rate;
  12.   int bonus;
  13. };
  14.  
  15. float calcSalary(struct person *firstPerson);
  16. void printSalary(struct person *firstPerson);
  17. void highestPaid(struct person *firstPerson);
  18.  
  19. int main() {
  20.   struct person persons[MAX_PERSON];
  21.   int n = 5, i;
  22.  
  23.   for (i=0; i<n; i++) {
  24.     printf("Please enter the name and surname of the person #%d: ", i+1);
  25.     scanf("%s %s", persons[i].name, persons[i].surname);
  26.  
  27.     printf("Please enter the number of hours worked by the person #%d: ", i+1);
  28.     scanf("%d", &persons[i].hours);
  29.  
  30.     printf("Please enter the hourly rate of the person #%d: ", i+1);
  31.     scanf("%f", &persons[i].rate);
  32.  
  33.     printf("Please enter the bonus rate of the person #%d (in percent): ", i+1);
  34.     scanf("%d", &persons[i].bonus);
  35.   }
  36.  
  37.   float totalSalary = calcSalary(persons);
  38.   printf("Total salary: %f\n", totalSalary);
  39.   printSalary(persons);
  40.   highestPaid(persons);
  41.  
  42.   return 0;
  43. }
  44.  
  45. float calcSalary(struct person *firstPerson) {
  46.   float totalSalary = 0.0;
  47.   int i;
  48.  
  49.   for (i=0; i<MAX_PERSON; i++) {
  50.     totalSalary = totalSalary + (firstPerson[i].hours * firstPerson[i].rate) +
  51.                   (firstPerson[i].hours * firstPerson[i].rate * (float)firstPerson[i].bonus / 100);
  52.   }
  53.  
  54.   return totalSalary;
  55. }
  56.  
  57. void printSalary(struct person *firstPerson) {
  58.   int i;
  59.  
  60.   for (i=0; i<MAX_PERSON; i++) {
  61.     float salary = (firstPerson[i].hours * firstPerson[i].rate) +
  62.                   (firstPerson[i].hours * firstPerson[i].rate * (float)firstPerson[i].bonus / 100);
  63.  
  64.     printf("%s %s salary is %f\n", firstPerson[i].name, firstPerson[i].surname, salary);
  65.   }
  66. }
  67.  
  68. void highestPaid(struct person *firstPerson) {
  69.   int i;
  70.   float highest = 0.0;
  71.   int highestIndex = 0;
  72.  
  73.   for (i=0; i<MAX_PERSON; i++) {
  74.     float salary = (firstPerson[i].hours * firstPerson[i].rate) +
  75.                   (firstPerson[i].hours * firstPerson[i].rate * (float)firstPerson[i].bonus / 100);
  76.  
  77.     if (salary > highest) {
  78.       highest = salary;
  79.       highestIndex = i;
  80.     }
  81.   }
  82.  
  83.   printf("The highest paid person is %s %s\n", firstPerson[highestIndex].name, firstPerson[highestIndex].surname);
  84. }
Advertisement
Add Comment
Please, Sign In to add comment