- #1

germana2006

- 42

- 0

// Program easy calculator

#include<stdio.h>

// Start the main program

int main (void)

{

//declaration of variables

double numb1, numb2, sol;

int op, menu;

begin: // Reference of the goto-

//To ask and read for the first number

printf("Give the first number:\n");

scanf("%lf",&numb1);

//Choice of one option: case1=+, case2=-, case3=*, case4=/

//First we have to break our program before case 5

//for that I use the do .. while loop

oper:

do { // do the next command while the condition is true

printf("Which operation do you want to do:\n");

printf("(1) Addition\n (2) Subtraction\n (3) Multiplication\n (4) Division\n");

scanf("%d",&op);

printf("Give the second number:\n");

scanf("%lf",&numb2);

switch (op){

//Addition of two numbers

case 1:

sol = numb1+numb2;

printf("The solution is:\n");

printf("sol=%lf\n",sol);

break;

//Subtraction of two numbers

case 2:

sol = numb1-numb2;

printf("The solution is:\n");

printf("sol=%lf\n",sol);

break;

//Multiplication of two numbers

case 3:

sol = numb1*numb2;

printf("The solution is:\n");

printf("sol=%lf\n",sol);

break;

//Division of two numbers

case 4:

//If the numb2 is 0, the division is not possible

if(numb2==0){

printf("The division is not possible!\n");

}

else{

sol = numb1/numb2;

printf("The solution is:\n");

printf("sol=%lf\n",sol);

}

break;

}

} while (op<=4);

/* The program should have a menu

* where one can choose one of this options

* (1) new calculation

* (2) other operation

* (3) finish */

printf("choose one option: (1) new calculation (2) other operation (3)finish \n");

scanf("%d",&menu);

if(menu==1 || menu==2 || menu==3){

if (menu==1){

goto begin;

}

if (menu==2){

numb1=sol;

goto oper;

}

if (menu==3){

printf("End");

}

}

return(0);

}