Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Simple Function Creation | Introduction
C++ Functions

bookChallenge: Simple Function Creation

Tarefa

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.

  1. Declare the function calculateTripCost that returns a double.
  2. Add a parameter to the function with type double named distanceKm.
  3. Calculate the total cost by multiplying distanceKm by perKmRate and adding the baseFare.
  4. 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

Solução

solution.cpp

solution.cpp

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 3
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you explain this in simpler terms?

What are the main takeaways from this?

Can you give me an example?

close

Awesome!

Completion rate improved to 5

bookChallenge: Simple Function Creation

Deslize para mostrar o menu

Tarefa

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.

  1. Declare the function calculateTripCost that returns a double.
  2. Add a parameter to the function with type double named distanceKm.
  3. Calculate the total cost by multiplying distanceKm by perKmRate and adding the baseFare.
  4. 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

Solução

solution.cpp

solution.cpp

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 3
single

single

some-alt