Vla_DOS

1

Jan 28th, 2023
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3.  
  4. typedef struct
  5. {
  6.     char firstName[50];
  7.     char lastName[50];
  8.     int hoursWorked;
  9.     float rate;
  10.     float bonusPercentage;
  11. } employee;
  12.  
  13. // function to load data
  14. void loadData(employee *e, char firstName[], char lastName[], int hoursWorked, float rate, float bonusPercentage){
  15.     strcpy(e->firstName, firstName);
  16.     strcpy(e->lastName, lastName);
  17.     e->hoursWorked = hoursWorked;
  18.     e->rate = rate;
  19.     e->bonusPercentage = bonusPercentage;
  20. }
  21.  
  22. // function to calculate salary
  23. int calculateSalary(employee *e){
  24.     return (e->hoursWorked * e->rate) + ((e->bonusPercentage/100) * (e->hoursWorked * e->rate));
  25. }
  26.  
  27. // function to display employee data
  28. void displayData(employee *e){
  29.     printf("First Name: %s\n", e->firstName);
  30.     printf("Last Name: %s\n", e->lastName);
  31.     printf("Hours Worked: %d\n", e->hoursWorked);
  32.     printf("Rate: %f\n", e->rate);
  33.     printf("Bonus Percentage: %f\n", e->bonusPercentage);
  34.     printf("Salary: %d\n", calculateSalary(e));
  35. }
  36.  
  37. int main()
  38. {
  39.     employee emp;
  40.     loadData(&emp, "John", "Doe", 40, 10.00, 0.10);
  41.     displayData(&emp);
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment