- You should really consider making functions for each mathematical operation and keep the
main()
simple.
As an example:
void addition(){
float num1, num2;
float result;
printf("Enter first number: ");
scanf("%f", &num1);
printf("Enter second number: ");
scanf("%f", &num2);
printf("\n");
result = num1 + num2;
printf("%.2f + %.2f = %.2f\n", num1, num2, result);
}
This way, you also create and destroy num1
num2
and result
each function call.
Consider asking the user if they would like to return to the menu, in case they want to do multiple calculations.
You don't need multiple
printf
statements for the menu options. Simply continuing as such is needed:printf("1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n\n");