I am new to C programming, I made a simple calculator program in C.
The program works, but does not work, it works until the value b is entered after it receives a symbol input and asks for input. I do not know why this is happening, but are there any problems?
here is my code:
#include <stdio.h> int main() { float a,b; char op; printf("enter a: "); scanf("%f",&a); printf("enter b: "); scanf("%f",&b); printf("enter operation: "); scanf("%c",&op); switch(op) { case '+': printf("\n%.2f %c %.2f = %.2f",a,op,b,a+b); break; case '-': printf("\n%.2f %c %.2f = %.2f",a,op,b,ab); break; case '*': printf("\n%.2f %c %.2f = %.2f",a,op,b,a*b); break; case '/': printf("\n%.2f %c %.2f = %.2f",a,op,b,a/b); break; default: printf("invallid input!!"); } return 0; }
The program seems to be absolutely correct, but there is still something that I am missing. Answers are welcome.
source share