You have been cordially invited to partake in Operation: Operation. Your mission, should you choose to accept it, is to take the two numbers and the operator given then perform the operation successfully.
Instructions:
Input
A line containing a number, operator, and another number separated by a space.
5·+·0.70
Output
A line containing a decimal/float containing two decimal places.
5.70
#include <stdio.h>
int main()
{
char op;
double firstOperand, secondOperand;
scanf("%lf %c %lf", &firstOperand, &op, &secondOperand);
switch (op)
{
case '+':
printf("%.2lf", firstOperand + secondOperand);
break;
case '-':
printf("%.2lf", firstOperand - secondOperand);
break;
case '*':
printf("%.2lf", firstOperand * secondOperand);
break;
case '/':
printf("%.2lf", firstOperand / secondOperand);
break;
default:
printf("Error! operator incorrect");
}
return 0;
}
Comments
Leave a comment