Create a Temperature Converter

CBeginner
Practice Now

Introduction

In this challenge, as a junior software developer at a weather app startup, you need to create a simple temperature conversion utility that helps travelers understand local temperatures in different units. The program should convert Celsius temperatures to Fahrenheit, using type casting to ensure accurate conversion and implementing the conversion formula using constant variables. The program should accept a Celsius temperature as input and display the Fahrenheit temperature with proper formatting.

Create a Temperature Converter

As a junior software developer at a weather app startup, you need to create a simple temperature conversion utility that helps travelers understand local temperatures in different units.

Tasks

  • Create a C++ program that converts Celsius temperatures to Fahrenheit
  • Use type casting to ensure accurate temperature conversion
  • Implement the conversion formula using const variables
  • Display the converted temperature with proper formatting

Requirements

  • Create a file named temperature_converter.cpp in the ~/project directory
  • Use const double to define the conversion formula
  • Implement explicit type casting when converting temperatures
  • The program should accept a Celsius temperature as input
  • Print the Fahrenheit temperature with two decimal places
  • Use the formula: F = (C * 9.0/5.0) + 32.0

Examples

## Compile the program
g++ -o temperature_converter temperature_converter.cpp

## Run the program
./temperature_converter
Enter temperature in Celsius: 25
25.00 Celsius is equal to 77.00 Fahrenheit
Enter temperature in Celsius: 0
0.00 Celsius is equal to 32.00 Fahrenheit
Enter temperature in Celsius: 100
100.00 Celsius is equal to 212.00 Fahrenheit

Hints

  • Use static_cast<>() for type conversion
  • Remember to include necessary headers like <iostream> and <iomanip>
  • Use std::fixed and std::setprecision() to format decimal output
  • Declare the conversion formula as a constant

Tips

  • In C++, integer division (9/5) results in 1, not 1.8
  • Always use floating-point values (9.0/5.0) to get accurate results
  • Write the formula as F = (C * 9.0/5.0) + 32.0 to avoid integer division issues
✨ Check Solution and Practice

Summary

In summary, this challenge requires you to create a C++ program that converts Celsius temperatures to Fahrenheit. The program should use type casting to ensure accurate temperature conversion, implement the conversion formula using constant variables, and display the converted temperature with proper formatting. The program should accept a Celsius temperature as input and output the corresponding Fahrenheit temperature.