36 lines
652 B
C
36 lines
652 B
C
#include "calculator.h"
|
|
#include <math.h>
|
|
#include <stdio.h>
|
|
|
|
/* - pekny vypis */
|
|
static void print_double(double x){
|
|
/* - cele cislo */
|
|
if (fabs(x - round(x)) < 1e-9) {
|
|
printf("%.0f\n", round(x));
|
|
return;
|
|
}
|
|
/* - min 2 des */
|
|
printf("%.2f\n", x);
|
|
}
|
|
|
|
int main(void){
|
|
char line[512];
|
|
|
|
/* - citaj riadky */
|
|
while (fgets(line,sizeof(line),stdin)){
|
|
double res;
|
|
|
|
/* - vypocitaj */
|
|
if (calc_evaluate(line,&res) != CALC_OK){
|
|
fprintf(stderr,"Chyba: %s\n", calc_error());
|
|
continue;
|
|
}
|
|
|
|
/* - vypis */
|
|
print_double(res);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|