Write a program that finds the temperature, as an integer, that is the same in both Celsius and Fahrenheit. The formula to convert from Celsius to Fahrenheit is as follows:
Fahrenheit = Celsius + 32
Your program should create two integer variables for the temperature in Celsius and Fahrenheit. Initialize the temperature to 100 degrees Celsius. In a loop, decrement the Celsius value and compute the corresponding temperature in Fahrenheit until the two values are the same.
C++ program Code:
//Header section
#include <iostream>
using namespace std;
//main method
int main()
{
// Initialize the temperature to 100 degrees Celsius
int celsius = 100;
//Declare variable
int fahrenheit;
// Decrement the Celsius value and compute the corresponding temperature in Fahrenheit
while (true)
{
// Convert Celsius to Fahrenheit using the formula
fahrenheit = (9 * celsius) / 5 + 32;
// Check if the Fahrenheit and Celsius values are the same
if (fahrenheit == celsius)
{
break; // Exit the loop if the values are the same
}
celsius--; // Decrement the Celsius value for the next iteration
}
//Display output
cout << "Temperature: " << celsius << " degrees Celsius / Fahrenheit" << endl;
return 0;
}
OUTPUT OF THE PROGRAM CODE:
Temperature: -40 degrees Celsius / Fahrenheit