Originally Posted by
sal92
How should I go from now using if/else to have those 4 choices?
I think a simple and effective way can be something like this:
Code:
if( choice == 1 )
printf( "\n\t%d + %d = %d\n\n", n1, n2, n1+n2 );
else if( choice == 2 )
printf( "\n\t%d x %d = %d\n\n", n1, n2, n1*n2 );
else if( choice == 3 )
printf( "\n\tsquare root of %d = %f\n\n", n1, sqrt(n1) );
else if( choice == 4 )
return 0;
Please, notice that choice has to be "==" (comparison) to the chosen number, not just "=" (assignment). Oh, and don't forget to include <math.h>, as sqrt() requires that library.
Can I say that I would add one more check, just to see if the user didn't type a valid choice?