My simple calculator is trying to display the chosen operation of the user. I understand that in C, strings must be declared as 1D char arrays.
int a, b;
int oper; //operation number
char operName[15];
printf("\nEnter two numbers: ");
scanf("%d%d", &a, &b);
printf("\nYou entered: %d and %d", a, b);
printf("\nChoose operation:"
"\n1 = +"
"\n2 = -"
"\n3 = x"
"\n4 = /");
scanf("%d", &oper);
The code compiles and runs. But when executing the switch block, it stops working. I'm using switch to choose the appropriate operation name, and assign it to operName (so I can display the chosen operation before I do the actual operation).
switch(oper){
case 1:
operName == "Addition";
break;
.
.
.
default:
operName == "Invalid input";
}
printf("\n\nYou chose: %s", oper);
I read somewhere that I need to use pointers to prevent memory leaks, but I'm new to this so maybe there's an easier way.