Skip to content

Commit

Permalink
Create Calculator.c
Browse files Browse the repository at this point in the history
  • Loading branch information
MR. ROBOT authored Oct 12, 2022
1 parent 003b719 commit 78ead55
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Calculator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int main(int argc, char *argv[])
{
float valueOne;
float valueTwo;
char operator;
float answer;

printf("Enter calculation:\n\n");
scanf("%f %c %f", &valueOne, &operator, & valueTwo);

switch(operator)
{
case '/': answer = valueOne/valueTwo;
break;
case '*': answer = valueOne*valueTwo;
break;
case '+': answer = valueOne+valueTwo;
break;
case '-': answer = valueOne-valueTwo;
break;
case '^': answer = pow(valueOne,valueTwo);
break;
case ' ': answer = sqrt(valueTwo);
break;
default: goto fail;
}
printf("%.9g%c%.9g = %.6g\n\n",valueOne,operator, valueTwo, answer);
goto exit;
fail:
printf("Fail.\n");
exit:
return 0;
}

0 comments on commit 78ead55

Please sign in to comment.