C Write a program that finds the temperature as an integer

C++

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: Fahrenheit = 32 + (nine fifths) times Celsius.


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.

Output should be:

The temperature is the same at -40

Solution

/* C++ Program with proper comments that finds the temperature, as an integer , that is the same in both Celsius and Fahrenheit. */ #include using namespace std; /*When we don\'t use the std namespace, the computer will try to call cout or cin as if it weren\'t defined in a namespace (as most functions in our codes). Since it doesn\'t exist there, the computer tries to call something that doesn\'t exist! Hence, an error occurs.*/ int toFahrenheit( int celsius ) { return ( ( 9.0 / 5 ) * celsius + 32 ); //returning the value of temp converted from C to F } int main() { int celsius; //temp variable in celsius int fahrenheit; //temp variable in Fahrenheit celsius = 100; while ( ( fahrenheit = toFahrenheit( celsius ) ) != celsius ) { celsius--; //keep decrementing celsius value until both values become equal } cout << \"The temperature is the same at \" << celsius // print same temp value with << endl; // required message return 0; }
C++ 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 Fahrenhe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site