some sums are going wrong like 321--
------------------------------------------------------------
Code:
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#define limit 10
int main() {
const char cont[100];
char temp[1], temp2[2];
float pilha_numeros[limit], pilha_numeros_final[limit], result;
int i, a = 0, what_byte, other_byte;
bool check = false;
float pilha_numero_int[100];
printf("INSERT: ");
scanf("%s", &cont);
for(i = 0; i < strlen(cont); i++) {
if(isdigit(cont[i])) {
//printf("now : %f\n", cont[i]);
pilha_numeros[a] = cont[i];
temp2[0] = pilha_numeros[a];
pilha_numero_int[a] = atof(temp2);
printf("%d= %f\n", (i+1),pilha_numero_int[a]);
a++;
} else {
what_byte = i - a +1;
if(check) {
other_byte = 0;
} else {
other_byte = what_byte - 1;
}
switch(cont[i]) {
case('+'):
//printf("\n first = %f[%f] | second = %f", pilha_numero_int[qual_byte], qual_byte, pilha_numero_int[other_byte]);
if(check) {
result = pilha_numero_int[what_byte] + pilha_numeros_final[other_byte];
} else {
result = pilha_numero_int[what_byte] + pilha_numero_int[other_byte];
}
pilha_numeros_final[0] = result;
//printf("\ntemp result = %f", result);
break;
case('-'):
if(check) {
result = pilha_numero_int[what_byte] - pilha_numeros_final[other_byte];
} else {
result= pilha_numero_int[what_byte] - pilha_numero_int[other_byte];
}
pilha_numeros_final[0] = result;
break;
case('*'):
if(check) {
result = pilha_numero_int[what_byte] * pilha_numeros_final[other_byte];
} else {
result = pilha_numero_int[what_byte] * pilha_numero_int[other_byte];
}
pilha_numeros_final[0] = result;
break;
case('/'):
if(check) {
result = pilha_numero_int[what_byte] / pilha_numeros_final[other_byte];
} else {
result = pilha_numero_int[what_byte] / pilha_numero_int[other_byte];
}
pilha_numeros_final[0] = result;
break;
}
check = true;
}
}
printf("\n\nResult = %f\n", pilha_numeros_final[0]);
}