Write a program that defines a(n):
- employee type (number, age, year of recrutement, salary)
- function that raises the salary of an employee by a certain percentage
Write a main function to test your functions.
Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
typedef struct {
int num;
int age;
int recruted;
double salary;
} employee;
employee raise(employee e, double percentage)
{
e.salary = e.salary * (1+percentage/100);
return e;
}
void main()
{
employee pierre = { 1035, 42, 1993, 2100.0 };
pierre = raise(pierre, 5);
printf("Pierre earns %.2f euros per month \n", pierre.salary);
return 0;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Calculate the sum of digits of an integer using recursion