Complier doesnt understand f and k in the cases
#include %26lt;stdio.h%26gt;
int main()
{
double a;
int w, c=0, f=0 ;
scanf("%d",%26amp;w);
switch (w){
case f:
scanf("%lf", %26amp;a);
printf("F %lf",32.0+1.8*a);
case k:
scanf("%lf", %26amp;a);
printf("K %lf",a+273);
}
return 0;
}
C programming problem... What should I do to convert celcius into f k? I have done something wrong ?
#include %26lt;stdio.h%26gt;
int main()
{
double a;
char w;
scanf("%d",%26amp;w);
switch (w)
{
case 'f':
scanf("%lf", %26amp;a);
printf("F %lf",32.0+1.8*a);
break;
case 'k':
scanf("%lf", %26amp;a);
printf("K %lf",a+273);
break;
default:
printf("\n Enter f for foreignfeet, k for kelvin\n");
}
return 0;
}
Reply:f and k will be interpreted as undefined variables.
try
case 'f':
case 'k':
Reply:the reason its not working is your using w that a int read in. and f that = 0 so unless someone puts 0 in w that statement has gone. case k wont ever come up either. i think you need to read in char* in stead of ints. it looks like that what your trying to do.
other than that it looks ok.
Reply:Learn how Switch() works too.
I dont think not using breaks is your intention.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment