[*]
You could do something like this:
#include<stdio.h>
int main(void){
int int1, int2, sum=0;
char op;
printf("Please enter one of the following Operators [*] [/] [+] [-] ");
if((scanf("%c",&op)) != 1){
printf("Error\n");
}
printf("Enter Value Here: ");
if((scanf("%d", &int1)) != 1){
printf("Error\n");
}
printf("Enter Value Here: ");
if((scanf("%d", &int2)) != 1){
printf("Error\n");
}
if (op == "https://stackoverflow.com/"){
sum = int1 / int2;
}else if(op == '*'){
sum = int1 * int2;
}else if(op == '+'){
sum = int1 + int2;
}else if(op == '*'){
sum = int1 - int2;
}
printf("The sum is %d\n", sum);
return 0;
}
Edit:
For a better precision you can use float or double, Use double if you are not sure.
#include<stdio.h>
int main(void){
float int1, int2, sum=0;
char op;
printf("Please enter one of the following Operators [*] [/] [+] [-] ");
if((scanf("%c",&op)) != 1){
printf("Error\n");
}
printf("Enter Value Here: ");
if((scanf("%f", &int1)) != 1){
printf("Error\n");
}
printf("Enter Value Here: ");
if((scanf("%f", &int2)) != 1){
printf("Error\n");
}
if (op == "https://stackoverflow.com/"){
sum = int1 / int2;
}else if(op == '*'){
sum = int1 * int2;
}else if(op == '+'){
sum = int1 + int2;
}else if(op == '*'){
sum = int1 - int2;
}
printf("The sum is %.1f\n", sum);
return 0;
}
4
[*]
solved Storing Char and using it in if-statements