Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Simple Function Creation | Introduction
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C++ Functions

bookChallenge: Simple Function Creation

Task

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 distance.
  3. Calculate the total cost by multiplying distance 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.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 3
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Simple Function Creation

Swipe to show menu

Task

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 distance.
  3. Calculate the total cost by multiplying distance 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.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 3
single

single

some-alt