Cpp - Write program to convert a temperate from Celsius to Fahrenheit

Requirements

Write a program that converts a temperate from Celsius to Fahrenheit.

Hint

The formula to do this is to multiply the Celsius temperate by 9, divide the result by 5, and then add 32.

Demo

#include <iostream>
  
float convert(float);
  
int main()//  w  ww. j  a va2 s  . co  m
{
    float fahrenheit;
    float celsius;
  
    std::cout << "Please enter the temperature in Celsius: ";
    std::cin >> celsius;
    fahrenheit = convert(celsius);
    std::cout << "\nHere's the temperature in Fahrenheit: ";
    std::cout << fahrenheit << "\n";
    return 0;
}
  
// function to convert Celsius to Fahrenheit
float convert(float celsius)
{
    float fahrenheit;
    fahrenheit = celsius * 9 / 5 + 32;
    return fahrenheit;
}

Result

Related Exercise