Challenge: Parking Fee Calculator
Oppgave
Swipe to start coding
You are building a parking management system. Each vehicle type pays a different fee depending on the parking zone.
- Check the car type using
ifandelse if:- If the car is
"compact", use aswitchstatement onzoneto assign the fee:- Zone 1 → $5.0
- Zone 2 → $3.0
- Other zones → $4.0
- If the car is
"SUV", use aswitchstatement onzoneto 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.
- If the car is
- Return the fee from the function.
Example
calculateParkingFee("compact", 1) → 5.0
calculateParkingFee("SUV", 3) → 7.0
calculateParkingFee("truck", 2) → 0.0
Løsning
solution.cpp
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 2. Kapittel 1
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 7.69
Challenge: Parking Fee Calculator
Sveip for å vise menyen
Oppgave
Swipe to start coding
You are building a parking management system. Each vehicle type pays a different fee depending on the parking zone.
- Check the car type using
ifandelse if:- If the car is
"compact", use aswitchstatement onzoneto assign the fee:- Zone 1 → $5.0
- Zone 2 → $3.0
- Other zones → $4.0
- If the car is
"SUV", use aswitchstatement onzoneto 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.
- If the car is
- Return the fee from the function.
Example
calculateParkingFee("compact", 1) → 5.0
calculateParkingFee("SUV", 3) → 7.0
calculateParkingFee("truck", 2) → 0.0
Løsning
solution.cpp
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 2. Kapittel 1
single