I am so confused with the module in C. I am writing a small script that allows the user to enter their two numbers-vars, then they can either add, subtract, multiply, divide (just) or the module (harbor "t caught it yet). What am I will I do it wrong? I get the error "invalid operands to binary%", which means that I need to format it to int, since this is a float. However, what is the best way to do 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 to do it?
source share