calculator to add,subtract,multiply,divide by using switch statement and infinite while loop statement
#include <stdio.h>
int main()
{
float a,b;
char input;
while(1)
{
printf("press 1 to add\n");
printf("press 2 to subtract\n");
printf("press 3 to multiply\n");
printf("press 4 to divide\n");
printf("press q to quit the program\n");
scanf(" %c", &input);
switch (input)
{
case 'q':
printf("The program is quitting......\n");
goto end;
break;
case '1':
printf("Enter first number to add\n");
scanf("%f",&a);
printf("Enter second number to add\n");
scanf("%f",&b);
printf("%f+%f = %f\n",a,b,a+b);
break;
case '2':
printf("Enter first number to subtract\n");
scanf("%f",&a);
printf("Enter second number to subtract\n");
scanf("%f",&b);
printf("%f-%f = %f\n",a,b,a-b);
break;
case '3':
printf("Enter first number to multiply\n");
scanf("%f",&a);
printf("Enter second number to multiply\n");
scanf("%f",&b);
printf("%f*%f = %f\n",a,b,a*b);
break;
case '4':
printf("Enter first number to divide\n");
scanf("%f",&a);
printf("Enter second number to divide\n");
scanf("%f",&b);
printf("%f/%f = %f\n",a,b,a/b);
break;
default:
printf("In defult now");
break;
}
}
end:
return 0;
}
Comments
Post a Comment