Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Parking Fee Calculator | Conditional Control Flow Practice
C++ Conditional Statements

bookChallenge: Parking Fee Calculator

Task

Swipe to start coding

You are building a parking management system. Each vehicle type pays a different fee depending on the parking zone.

  1. Check the car type using if and else if:
    • If the car is "compact", use a switch statement on zone to assign the fee:
      • Zone 1 β†’ $5.0
      • Zone 2 β†’ $3.0
      • Other zones β†’ $4.0
    • If the car is "SUV", use a switch statement on zone to assign the fee:
      • Zone 1 β†’ $8.0
      • Zone 2 β†’ $6.0
      • Other zones β†’ $7.0
    • For other car types, set the fee to $0.0.
  2. Return the fee from the function.

Example

calculateParkingFee("compact", 1) β†’ 5.0
calculateParkingFee("SUV", 3) β†’ 7.0
calculateParkingFee("truck", 2) β†’ 0.0

Solution

solution.cpp

solution.cpp

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 1
single

single

Ask AI

expand

Ask AI

ChatGPT

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

close

Awesome!

Completion rate improved to 7.69

bookChallenge: Parking Fee Calculator

Swipe to show menu

Task

Swipe to start coding

You are building a parking management system. Each vehicle type pays a different fee depending on the parking zone.

  1. Check the car type using if and else if:
    • If the car is "compact", use a switch statement on zone to assign the fee:
      • Zone 1 β†’ $5.0
      • Zone 2 β†’ $3.0
      • Other zones β†’ $4.0
    • If the car is "SUV", use a switch statement on zone to assign the fee:
      • Zone 1 β†’ $8.0
      • Zone 2 β†’ $6.0
      • Other zones β†’ $7.0
    • For other car types, set the fee to $0.0.
  2. Return the fee from the function.

Example

calculateParkingFee("compact", 1) β†’ 5.0
calculateParkingFee("SUV", 3) β†’ 7.0
calculateParkingFee("truck", 2) β†’ 0.0

Solution

solution.cpp

solution.cpp

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Β 2. ChapterΒ 1
single

single

some-alt