Created
March 3, 2016 01:50
-
-
Save novasdream/df57192af46a1bb17c5c 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> | |
#include <stdlib.h> | |
#include <locale.h> | |
enum { | |
SUM = '+', | |
MULT = '*', | |
SUB = '-', | |
DIVISION = '/' | |
} ; | |
float total = 0; | |
int op_n = 1; | |
int main() | |
{ | |
char operation = '+'; | |
float var1 = 0; | |
float var2 = 0; | |
printf("Olaa Usuario !\n Voce precisa inserir os dados no padrao.\n1.5+25\n\nOu Semelhante.\n\n"); | |
scanf("%f%c%f", &var1,&operation,&var2 ); | |
char selected ; | |
while(1){ | |
if(total != 0){ | |
scanf("%c%f", &operation,&var2 ); | |
} | |
switch(operation){ | |
case '+': | |
selected = SUM; | |
break; | |
case '-': | |
selected = SUB; | |
break; | |
case '/': | |
selected = DIVISION; | |
break; | |
case '*': | |
selected = MULT; | |
break; | |
default: | |
printf("Informe corretamente a operação"); | |
exit(1); | |
} | |
if(total != 0){ | |
calcular(selected, &total, &var2); | |
} else { | |
calcular(selected, &var1, &var2); | |
} | |
} | |
return 0; | |
} | |
void calcular(char sel, float *var1, float *var2){ | |
switch( sel ){ | |
case SUM: | |
total = (*var1 + *var2); | |
break; | |
case SUB: | |
total = (*var1 - *var2); | |
break; | |
case MULT: | |
total = (*var1 * *var2); | |
break; | |
case DIVISION: | |
total = (*var1 / *var2); | |
break; | |
} | |
op_n++; | |
fflush(stdin); | |
printf("%4.2f %1c %4.2f = %.2f\n", *var1, sel, *var2, total); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment