Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- It is a simple calculator able to operate over just two numbers.
- */
- #include <stdio.h>
- int main(){
- float a, b;
- char op;
- do{
- printf("\nEnter a, b: ");
- scanf("%f %f", &a, &b);
- printf("\nChoose among the operation (+, -, *, /,) or hit E to exit: ");
- scanf("%c", &op);
- op = getchar();
- if(op == '+')
- printf("\nResult = %.2f\n", a + b);
- else if(op == '-')
- printf("\nResult = %.2f\n", a - b);
- else if(op == '*')
- printf("\nResult = %.2f\n", a * b);
- else if(op == '/')
- printf("\nResult = %.2f\n", a / b);
- else if(op == 'E')
- printf("\nEnd!\n");
- else
- printf("\nInvalid!\n");
- } while(op != 'E');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement