I want someone to run the code, you will find that the code at line number 14 to 17, I don't what this error is. I am giving my code along with this error image.
/*
A simple calculator made with if-else and switch case
*/
#include <stdio.h>
int main() {
// if-else
char _opt_1;
float x_1, x_2;
printf("Enter a valid operator from (+ , - , * , /: ");
scanf("%c", &_opt_1);
printf("Enter first number: ");
scanf("%f", &x_1);
printf("Enter second number: ");
scanf("%f", &x_2);
if(_opt_1=='+') {
printf("The sum is: %f \n", x_1+x_2);
}else if(_opt_1=='-') {
printf("The sum is: %f \n", x_1-x_2);
}else if(_opt_1=='*') {
printf("The sum is: %f \n", x_1*x_2);
}else if(_opt_1=='/') {
printf("The sum is: %f \n", x_1/x_2);
}else{
printf("Please enter a valid operator \n");
}
// switch case
char operator;
float x, y;
printf("Enter the operation you want to perform like (+,-,*,/): ");
scanf("%c", &operator);
printf("Enter the first number: ");
scanf("%f", &x);
printf("Enter the second number: ");
scanf("%f", &y);
switch(operator) {
case '+':
printf("The sum is: %f", x + y);
break;
case '-':
printf("The difference is: %f", x - y);
break;
case '*':
printf("The product is: %f", x * y);
break;
case '/':
printf("The division is: %f", x / y);
break;
default:
printf("Please enter a valid operator");
}
return 0;
}