switch statement doesnt work!!!!

#include <iostream.h>
#include <iomanip.h>

void main()
{
int dir=90;
float fah,cel;
cout << "Type 1 to convert Fah to Cel,\n 2 to convert Cel to Fah";
cin >> dir;
switch(dir) {
case '1':
cout << "Enter temp in Fah: ";
cin >> fah;
cel=(fah-32)*5/9;
cout << "In Cel that's " << cel<< endl;
break;
case '2':
cout << "Enter temp in Cel: ";
cin >> cel;
fah=cel*9/5-32;
cout << "In fah that's " << fah<< endl;
break;
default: cout << endl;
}
}
Last edited on
dir is of type int, but in the switch statement you treat it as if it was a char. You need to write:

1
2
switch(dir) {
		case 1:



Fafner
Topic archived. No new replies allowed.