Temperature Conversion Program

temp-f2c.cpp

Download file: Windows | macOS | Unix

 1// Program    : Temperature Conversion - Fahrenheit to Celsius
 2// Author     : Prof. Krofchok
 3// Date       : Fall 2025
 4// Description: Converts a temperature input by the user from Fahrenheit
 5//              to Celsius.
 6
 7#include <iomanip>
 8#include <iostream>
 9
10void input_data(double &fahrenheit);
11void perform_calculations(double fahrenheit, double &celsius);
12void output_results(double fahrenheit, double celsius);
13
14int main()
15{
16    double fahrenheit;  // temperature input by user
17    double celsius;     // calculated equivalent temperature
18
19    input_data(fahrenheit);
20    perform_calculations(fahrenheit, celsius);
21    output_results(fahrenheit, celsius);
22}
23
24//
25// An input module that gets a Fahrenheit temperature from the user.
26//
27void input_data(double &fahrenheit)
28{
29    std::cout << "Enter temperature in Fahrenheit: ";
30    std::cin >> fahrenheit;
31}
32
33//
34// A processing module that computes the Celsius temperature that is
35// equivalent to the given Fahrenheit temperature.
36//
37void perform_calculations(double fahrenheit, double &celsius)
38{
39    celsius = (5.0 / 9.0) * (fahrenheit - 32.0);
40}
41
42//
43// An output module that displays a Fahrenheit temperature and its Celsius
44// equivalent.
45//
46void output_results(double fahrenheit, double celsius)
47{
48    std::cout << std::fixed << std::setprecision(1);
49    std::cout << fahrenheit << " Fahrenheit = ";
50    std::cout << celsius << " Celsius" << std::endl;
51}