Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef struct
- {
- char firstName[50];
- char lastName[50];
- int hoursWorked;
- float rate;
- float bonusPercentage;
- } employee;
- // function to load data
- void loadData(employee *e, char firstName[], char lastName[], int hoursWorked, float rate, float bonusPercentage){
- strcpy(e->firstName, firstName);
- strcpy(e->lastName, lastName);
- e->hoursWorked = hoursWorked;
- e->rate = rate;
- e->bonusPercentage = bonusPercentage;
- }
- // function to calculate salary
- int calculateSalary(employee *e){
- return (e->hoursWorked * e->rate) + ((e->bonusPercentage/100) * (e->hoursWorked * e->rate));
- }
- // function to display employee data
- void displayData(employee *e){
- printf("First Name: %s\n", e->firstName);
- printf("Last Name: %s\n", e->lastName);
- printf("Hours Worked: %d\n", e->hoursWorked);
- printf("Rate: %f\n", e->rate);
- printf("Bonus Percentage: %f\n", e->bonusPercentage);
- printf("Salary: %d\n", calculateSalary(e));
- }
- int main()
- {
- employee emp;
- loadData(&emp, "John", "Doe", 40, 10.00, 0.10);
- displayData(&emp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment