I want the user to enter a value liked ADD or SUB to perform the desired operation but I'm getting "array subscript is not a integer instead". I know I can enter digits instead like 0, 1 , 2 etc. because of how enums work but I want to make it more user friendly. I can't find any information online about this as well, and my books are of not helping. Help please!
#include<stdio.h>
#include<stdlib.h>
int multiply(int , int);
int sum(int, int);
int divide(int, int);
int sub(int, int);
int(*calc[])(type) = {sum, sub, multiply, divide};
enum response{ADD, SUB, MULT, DIV};
enum response type;
int main()
{
int a, b;
char s[4];
printf("Enter two numbers and the operation. Operations: ADD, SUB, MULT, DIV");
scanf("%d %d %s", &a, &b, &s);
printf("The result = %d",(calc[s])(a, b));
return 0;
}
int multiply(int a, int b)
{
return a*b;
}
int sub(int a, int b)
{
return a-b;
}
int sum(int a, int b)
{
return a+b;
}
int divide(int a, int b)
{
return a/b;
}