I am making a calculator in c, everything works except when using the division command "/"
When a number is divided by 0 it should print out "NaN" and then exiting the program. However the output is: NaN0.0
Meaning that the function is also returning the value of the float despite using the return 0 command.
How do i make it so that the function just returns "NaN"?
float calc(float param1, char operator1, float param2){
#include <math.h>
float result;
switch(operator1){
case '+':
result = param1 + param2;
return result;
break;
case '-':
result = param1 - param2;
return result;
break;
case '*':
result = param1 * param2;
return result;
break;
case'/':
if(param2 == 0){printf("NaN"); //Issue here
return 0;
}
else{
result = param1 / param2;}
return result;
break;
case '^':
result = pow(param1, param2);
return result;
}
}