Write a function definition for a function called Bonus that

Write a function definition for a function called Bonus that takes one argument of type double the regular salary of an employee and returns a double, the new salary with the bonus. The function will prompt the user for the percentage to be added to the salary, calculate the bonus amount, add it to the base salary and return the new salary with the bonus. Declare any additional variables needed.

For example if the base salary was 10000.00 and the user entered .03 for three percent, the new salary 10300.00 would be returned.

Solution

// C code to find salary after bonus

#include <stdio.h>
#include <stdlib.h>

double bonus(double regularSalary)
{
   double bonus;
   printf(\"Enter bonus percentage: \");
   scanf(\"%lf\",&bonus);

   double salary = regularSalary*(1+bonus);

   return salary;
}


int main()
{
   double regularSalary;
   printf(\"Enter regular salary: \");
   scanf(\"%lf\",&regularSalary);

   printf(\"\ Salary with bonus: %0.2lf\ \",bonus(regularSalary));  

   return 0;
}

/*
output:

Enter regular salary: 10000.00
Enter bonus percentage: .03

Salary with bonus: 10300.00

*/

Write a function definition for a function called Bonus that takes one argument of type double the regular salary of an employee and returns a double, the new s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site