- #1
burton95
- 54
- 0
I must write a program that finds the temperature, as an integer, that is the same in both Celsius and Fahrenheit. The formula for this is
F=(9/5)C+32
The 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 values are the same.
my code
Answer is - 40 but I keep getting -43. What am I missing? I tried changing int to doubles and then it wouldn't run. Thanks
Anthony
F=(9/5)C+32
The 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 values are the same.
my code
Code:
#include <iostream>
using namespace std;
int main()
{
int c_temp = 100;
int f_temp = 212; while (c_temp != f_temp)
{
f_temp = ((9 * c_temp) / 5) + 32;
c_temp--;
}
cout << "The temperature when they are both the same is: " << c_temp << endl;
}
Anthony
Last edited by a moderator: