I am so confused with Modulus in C. I am writing a small script that allows the user to input their two number vars, then they can either add, subtract, multiply, divide (easy) or modulus (haven't caught this one yet). What would I be doing wrong in this? I get the "invalid operands to binary %" error, which means I need to format it to an int since it is a float. However what is the best way of doing this with the following? Any C help would be greatly appreciated.
int main (void)
{
float number1, number2, result;
char symbol;
//allow user interaction
printf("Enter your formula: \n");
scanf("%f %c %f", &number1, &symbol, &number2);
switch (symbol) {
case '%':
result = number1 % number2;
printf("Result: %f \n", result);
break;
default:
printf("Operation Error. Program aborted. \n \n");
break;
}
printf("Press any key to continue \n");
getchar();
return 0;
}
Where and how do I convert this?