Challenge: Simple Function Creation
Swipe to start coding
You are building a ride-sharing app. Each ride has a distance in kilometers, and you want to calculate the total cost based on a base fare and a per-kilometer rate.
- Declare the function
calculateTripCost
that returns adouble
. - Add a parameter to the function with type
double
nameddistanceKm
. - Calculate the total cost by multiplying
distanceKm
byperKmRate
and adding thebaseFare
. - Return the total cost from the function.
Do not modify the values of baseFare
and perKmRate
inside the calculateTripCost
function.
Example
calculateTripCost(12.5)
→ 30.0
calculateTripCost(0)
→ 5.0
calculateTripCost(7)
→ 19.0
Рішення
solution.cpp
Дякуємо за ваш відгук!
single
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Can you explain this in simpler terms?
What are the main takeaways from this?
Can you give me an example?
Awesome!
Completion rate improved to 5
Challenge: Simple Function Creation
Свайпніть щоб показати меню
Swipe to start coding
You are building a ride-sharing app. Each ride has a distance in kilometers, and you want to calculate the total cost based on a base fare and a per-kilometer rate.
- Declare the function
calculateTripCost
that returns adouble
. - Add a parameter to the function with type
double
nameddistanceKm
. - Calculate the total cost by multiplying
distanceKm
byperKmRate
and adding thebaseFare
. - Return the total cost from the function.
Do not modify the values of baseFare
and perKmRate
inside the calculateTripCost
function.
Example
calculateTripCost(12.5)
→ 30.0
calculateTripCost(0)
→ 5.0
calculateTripCost(7)
→ 19.0
Рішення
solution.cpp
Дякуємо за ваш відгук!
single