After execution, it asks me to enter temperature, enter unit and then a debug error (run time check error 3 - the variable Fahrenheit is being used without being initialized)
Well, yeah. Look at line 25. What is the value of celsius?
Line 30: What is the value of farhenheit when this line is executed?
Hint: In both cases the values are garbage because you never initialized them, which is exactly what the debug error is trying to tell you.
Line 25,30: Don't you mean to use temperature instead of celcuis or farhenheit on the right side of the calculations?
#include <iostream>
usingnamespace std;
int main()
{
int temperature=0;
char unit;
double fahrenheit;
double celsius;
while (temperature<999)
{
cout<<"Enter temperature: ";
cin>>temperature;
cout<<"Enter unit: ";
cin>>unit;
if (unit=='F')
{
celsius=((temperature-32)*5)/9;
cout<<"Temperature in celcius is: "<<celsius<<endl;
}
else
{
fahrenheit=(((temperature*9)/5)+32);
cout<<"Temperature in farhenheit is: "<<fahrenheit<<endl;
}
}
return 0;
}
Now program should stop if I enter temperature 999 or more, but it converts the value.
How should I ask program to stop conversion when temperature>999?