Compute an end-of-year performance bonus for one employee, then print the employee's name and the bonus.
You start with:
let name = "John Doe"
let productivity = 83
let salary = 135000
Build:
John Doe Bonus: $20250
Rules:
- The bonus is 15% of the
salary, rounded down to a whole number. - Print the employee's
nameon the first line. - Print the bonus on the second line as
"Bonus: $<amount>". productivityis not used in this version. It is there for the next versions, where you will compare employees by productivity.
Dividing two whole numbers (
Int) drops the fraction, so salary * 15 / 100 is already rounded down: let bonus = salary * 15 / 100
Convert the number with
String(...) (or use \(...) inside the text): print("Bonus: $\(bonus)")
let name = "John Doe"
let productivity = 83
let salary = 135000
let bonus = salary * 15 / 100
print(name)
print("Bonus: $\(bonus)")
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
