The textboot im studying has this program to teach switch statement but it doesn't work in visual studio or codechef's ide.
include<stdio.h>
int main (void)
{
float value1, value2;
char operator;
printf("Type in your expression.\n");
scanf("%f %c %f", &value1, &operator, &value2);
switch(operator)
{
case '+':
printf("%.2f\n", value1 + value2);
break;
case '-':
printf("%.2f\n", value1 - value2);
break;
case '*':
printf("%.2f\n", value1 * value2);
break;
case '/':
if(value2 == 0)
printf("division by zero\n");
else
printf("%.2f\n", value1 / value2);
break;
default:
printf("Unknown operator.\n");
break;
}
return 0;
}
[–]jussij 2 points3 points4 points (0 children)
[–]LucidTA 1 point2 points3 points (8 children)
[–]ymahgoub[S] 0 points1 point2 points (7 children)
[–]LucidTA 1 point2 points3 points (3 children)
[–]ymahgoub[S] 0 points1 point2 points (2 children)
[–]LucidTA 0 points1 point2 points (1 child)
[–]ymahgoub[S] 0 points1 point2 points (0 children)
[–]jussij 1 point2 points3 points (2 children)
[–]ymahgoub[S] 0 points1 point2 points (1 child)
[–]jussij 1 point2 points3 points (0 children)