Challenge: Understanding Variable Scopes
Swipe to start coding
You are building a simple tax calculator. Each user has a salary, and you want to calculate the amount of tax they need to pay based on a fixed tax rate.
- Declare the function
calculateTax
that returns adouble
. - Add a parameter to the function with type
double
namedsalary
. - Calculate the tax by multiplying
salary
bytaxRate
. Usedouble taxRate = 0.18
as the fixed rate. - Return the calculated tax from the function.
Do not modify the value of taxRate
inside the calculateTax
function.
Example
calculateTax(2500.0)
→ 450.0
calculateTax(1000.0)
→ 180.0
calculateTax(0)
→ 0.0
Solución
solution.cpp
¡Gracias por tus comentarios!
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Awesome!
Completion rate improved to 5
Challenge: Understanding Variable Scopes
Desliza para mostrar el menú
Swipe to start coding
You are building a simple tax calculator. Each user has a salary, and you want to calculate the amount of tax they need to pay based on a fixed tax rate.
- Declare the function
calculateTax
that returns adouble
. - Add a parameter to the function with type
double
namedsalary
. - Calculate the tax by multiplying
salary
bytaxRate
. Usedouble taxRate = 0.18
as the fixed rate. - Return the calculated tax from the function.
Do not modify the value of taxRate
inside the calculateTax
function.
Example
calculateTax(2500.0)
→ 450.0
calculateTax(1000.0)
→ 180.0
calculateTax(0)
→ 0.0
Solución
solution.cpp
¡Gracias por tus comentarios!
single