Hi
I was doing this program on Visual Studio 2005 where the program converts C to F and vise versa but after debugging it, it doesnt give the expected result. Could someone tell me what is wrong with my code???
#include <iostream>
#include <iomanip>
using namespace::std;
using std::fixed;
int main()
{
int conversionType = 0;
double temp = 0.0;
double result = 0.0;
cout << "Enter -1 (F to C) or 2 (C to F): ";
cin >> conversionType;
cout << "Enter temperature: ";
cin >> temp;
if (conversionType == '-1')
{
result = (temp - 32) * 5 / 9 ;
}
else if (conversionType == '2')
{
result = temp * 9/5 + 32;
} //end if
cout << "Result: " << result << endl;
return 0;
} //end of main function
I was doing this program on Visual Studio 2005 where the program converts C to F and vise versa but after debugging it, it doesnt give the expected result. Could someone tell me what is wrong with my code???
#include <iostream>
#include <iomanip>
using namespace::std;
using std::fixed;
int main()
{
int conversionType = 0;
double temp = 0.0;
double result = 0.0;
cout << "Enter -1 (F to C) or 2 (C to F): ";
cin >> conversionType;
cout << "Enter temperature: ";
cin >> temp;
if (conversionType == '-1')
{
result = (temp - 32) * 5 / 9 ;
}
else if (conversionType == '2')
{
result = temp * 9/5 + 32;
} //end if
cout << "Result: " << result << endl;
return 0;
} //end of main function
Comment