Skip to content

Instantly share code, notes, and snippets.

@EvanCarroll
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanCarroll/c73f9cbfdecb4b50b91c to your computer and use it in GitHub Desktop.
Save EvanCarroll/c73f9cbfdecb4b50b91c to your computer and use it in GitHub Desktop.
#include <stdio.h>
/* Program to evaluate simple expressions (value operator value)*/
int main() {
float value1, value2;
char operator;
for (int count = 1; count <= 3; count++) {
printf("What are your value opreator and value (seperate with Enter)?\n");
scanf("%f %c %f", &value1, &operator, &value2);
switch (operator) {
case '+':
printf("%.2f\n", value1 + value2);
break;
case '-':
printf("%.2f\n", value1 - value2);
break;
case '*':
printf("%.2f\n", value1 * value2);
break;
case '\/':
if (value2 == 0) {
printf("Division by zero!\n");
}
else {
printf("%.2f\n", value1 / value2);
}
break;
default:
printf("Invalid value!\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment