Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Temperature Converter | Introduction to Exceptions
C++ Exception Handling

bookChallenge: Temperature Converter

In this challenge, your task is to implement a robust temperature conversion function using exception handling. You need to write a function that converts a temperature from Celsius to Kelvin.

The Kelvin scale does not allow negative values, and the lowest possible temperature in Celsius is -273.15, known as absolute zero. If the input temperature is below this limit, your function should throw an exception to signal that the conversion is invalid.

This exercise will help you practice detecting invalid input and using exceptions to enforce constraints in your code.

Taak

Swipe to start coding

Your goal is to create a function that converts a temperature value from Celsius to Kelvin. The Kelvin temperature scale does not permit negative values, so the lowest valid Celsius value is -273.15 (absolute zero).

If the input temperature is less than -273.15, your function must throw an exception to indicate the input is invalid. Otherwise, the function should return the temperature converted to Kelvin.

Use exception handling to ensure your function behaves correctly for both valid and invalid input.

Oplossing

solution.cpp

solution.cpp

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 4
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

close

Awesome!

Completion rate improved to 6.67

bookChallenge: Temperature Converter

Veeg om het menu te tonen

In this challenge, your task is to implement a robust temperature conversion function using exception handling. You need to write a function that converts a temperature from Celsius to Kelvin.

The Kelvin scale does not allow negative values, and the lowest possible temperature in Celsius is -273.15, known as absolute zero. If the input temperature is below this limit, your function should throw an exception to signal that the conversion is invalid.

This exercise will help you practice detecting invalid input and using exceptions to enforce constraints in your code.

Taak

Swipe to start coding

Your goal is to create a function that converts a temperature value from Celsius to Kelvin. The Kelvin temperature scale does not permit negative values, so the lowest valid Celsius value is -273.15 (absolute zero).

If the input temperature is less than -273.15, your function must throw an exception to indicate the input is invalid. Otherwise, the function should return the temperature converted to Kelvin.

Use exception handling to ensure your function behaves correctly for both valid and invalid input.

Oplossing

solution.cpp

solution.cpp

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 4
single

single

some-alt