Last active
August 29, 2015 14:05
-
-
Save EvanCarroll/c73f9cbfdecb4b50b91c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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