Questions: Declare and define a function that computes bonus for an employee depending on the base salary and the number of years of experience of the employee. Inside the function, check the number of years of experience. If the number of years of experience is greater than 10 years, the bonus is 5% of the base salary, otherwise it is 3% of the base salary. You will need to call this function from your main function and pass the base salary and the number of years as arguments.

Declare and define a function that computes bonus for an employee depending on the base salary and the number of years of experience of the employee.
Inside the function, check the number of years of experience. If the number of years of experience is greater than 10 years, the bonus is 5% of the base salary, otherwise it is 3% of the base salary. You will need to call this function from your main function and pass the base salary and the number of years as arguments.
Transcript text: Declare and define a function that computes bonus for an employee depending on the base salary and the number of years of experience of the employee. Inside the function, check the number of years of experience. If the number of years of experience is greater than 10 years, the bonus is $5 \%$ of the base salary, otherwise it is $3 \%$ of the base salary. You will need to call this function from your main function and pass the base salary and the number of years as arguments.
failed

Solution

failed
failed

Certainly! Below is the corrected and completed version of the program based on the provided template. The function compute_bonus calculates the bonus based on the base salary and years of experience, and the main function gets the input from the user, calls the compute_bonus function, and displays the result.

#include <iostream>
using namespace std;

// Function declaration
double compute_bonus(double base_salary, int experience);

int main() {
    double base_salary;
    int experience;

    // Get the values of base salary and experience from the user
    cout << "Enter the base salary: ";
    cin >> base_salary;
    cout << "Enter the number of years of experience: ";
    cin >> experience;

    // Call compute_bonus by passing necessary parameters
    double bonus = compute_bonus(base_salary, experience);

    // Display the bonus returned by the function
    cout << "The bonus is: $" << bonus << endl;

    return 0;
}

// Function definition
double compute_bonus(double base_salary, int experience) {
    if (experience > 10) {
        return base_salary * 0.05;
    } else {
        return base_salary * 0.03;
    }
}
Explanation:
  1. Function Declaration and Definition:

    • The function compute_bonus is declared to take two parameters: double base_salary and int experience.
    • Inside the function, a conditional check determines the bonus percentage based on the number of years of experience. If the experience is greater than 10 years, the bonus is 5% of the base salary; otherwise, it is 3%.
  2. Main Function:

    • The main function prompts the user to enter the base salary and the number of years of experience.
    • It then calls the compute_bonus function with these inputs and stores the returned bonus.
    • Finally, it displays the calculated bonus.

This program correctly implements the required functionality and follows the given template.

Was this solution helpful?
failed
Unhelpful
failed
Helpful