Question: B. More Variables In this program, we will compute the bonus earned by an employee and display the result on the screen. Write a C++
B. More Variables
In this program, we will compute the bonus earned by an employee and display the result on the screen.
Write a C++ program called Lab3B.cpp that does the following:
-
Using a suitable message, prompt for and read in the full name of the employee and save it in a string variable called name. Note that the name can have more than one word, so you need to use the getline function.
-
Using a suitable message, prompt for and read in the salary of the employee and save it in a double variable called salary.
-
Using a suitable message, prompt for and read in the percentage rate of bonus computation and save it in an integer variable called rate. Assume the user will enter a value between 1 and 10.
-
Now compute the bonus earned by the employee by using the following formula: = (/100)
and store the result in a double variable called bonus. You must use the formula as it is provided: DO NOT remove the parenthesis and DO NOT change 100 to a floating point number such as 100.0 or 100.00.
2
Finally display the result in the following format:Employee_name earned a bonus of XXXX.XX
Employee_name must be replaced by the name entered by the user, andXXXX.XX must be replaced by the bonus computed by your program.
If you used the formula as it is, you probably got 0 as the bonus. Think why? HINT: Integer Division and Typecasting. Fix your code to get the correct bonus value by using the static_cast function.
Make sure you display exactly two numbers after the decimal point.
Before writing the code, you may want to write out the algorithm, or steps, on paper of how you propose to solve this problem. Working out the arithmetic by hand is also recommended to insure that you are outputting the correct values for each variable.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
