Make this code better

Calclator using switch statement for various operations

I designed and devised this calculator on my own, from scratch. My idea is to let the user choose the operation they want to perform on the two numbers they will input, and the computer will then output the statement corresptonding to each case.

The code compiles and everything, but when I try to select the operation, the process stops responding, and I am forced to quit it manually. Any help is much appreciated.



// Calculator program for any 2 numbers. Portfolio Extra submission. #include <stdio.h> #include <math.h> int main(){ int op, a, b; printf("Select the operation you wish to perform:\n 1. Addition \n 2. Subtraction \n 3. Multiplication \n 4. Division \n"); scanf("%f, op"); printf("Please enter below the two numbers you wish to perform your selected operation on: \n"); scanf("%lf", a); scanf("%lf", a); switch (op) { case 1: printf("%lf minus %lf is equal to %lf", a, b, (a+b)); case 2: printf("%lf minus %lf is equal to %lf", a, b, (a-b)); case 3: printf("%lf times %lf is equal to %lf", a, b, (a*b)); case 4: printf("%lf divided by %lf is equal to %lf", a, b, (a/b)); } return 0; }

Reactions 0 reactions

No reactions yet, be the first: comment or tweak the code

Comment on this code:

Please Login or Register to leave a comment.