+ 1
What's wrong with the following . Its simple calculator but not working correctly on computer as well as mobile.
#include<stdio.h> int main() { float a,b; char c; printf("Enter two numbers\n"); scanf("%f%f",&a,&b); printf("press + for addition - for subtraction * for multiplication or / for division\n"); scanf("%c",&c); switch(c) { case '+' : printf("%f + %f = %f",a,b,a+b); break; case '-': printf("%f - %f = %f",a,b,a-b); break; case '*' : printf("%f * %f = %f",a,b,a*b); break; case '/' : printf("%f / %f = %f",a,b,a/b); break; default : printf("Entered Wrong Choice"); } }
2 odpowiedzi
+ 4
Two options:-
printf("Enter two numbers\n");
scanf("%f %f",&a,&b);
fflush(stdin); // add this...or
printf("press + for addition - for subtraction * for multiplication or / for division\n");
scanf(" %c",&c); // put a space just before the %c.
0
Yes it works but please can you tell me why space is necessary before the %c.