162k views
3 votes
How do I fix when it hits the second session it skips scanf.

#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
main() {
double first, second;
while(1){
printf(" Calculator\\");
printf("\\ 7 8 9 / \\ 4 5 6 x \\ 1 2 3 - \\Enter operator: ");
char op;
scanf("%c" ,&op); //entering operators such as + - \ *
printf("Enter two operands:");
scanf("%lf %lf", &first, &second); //entering operands such as 1 2 5 8 12 414
switch (op) { // printing the math
case '+'://if its +
printf("%.1lf + %.1lf = %lf\\\\", first, second, first + second);
break;
case '-'://if its -
printf("%.1lf - %.1lf = %lf\\\\", first, second, first - second);
break;
case '*'://if its *
printf("%.1lf * %.1lf = %lf\\\\", first, second, first * second);
break;
case '/'://if its :
printf("%.1lf / %.1lf = %lf\\\\", first, second, first / second);
break;
default://if its not + - / *
printf("error!");
}
}
}

1 Answer

4 votes

Answer:

scanf(" %c" ,&op); //entering operators such as + - \ *

Step-by-step explanation:

put space before %c

User Manoj Savalia
by
4.7k points