42 lines
1.1 KiB
C
42 lines
1.1 KiB
C
#include "calculator.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
|
|
#define MAX_INPUT_LENGTH 256
|
|
|
|
int main() {
|
|
char input[MAX_INPUT_LENGTH];
|
|
printf("=== Vedecka kalkulacka ===\n");
|
|
printf("Podporovane operacie: + - * / ( )\n");
|
|
printf("Funkcie: sin(), cos(), sqrt(), log()\n");
|
|
printf("Mocnina: ^ (napr. 2^3 = 8)\n");
|
|
printf("Pre ukoncenie napiste 'koniec'\n\n");
|
|
while (1) {
|
|
printf("Zadajte vyraz: ");
|
|
if (fgets(input, sizeof(input), stdin) == NULL) {
|
|
break;
|
|
}
|
|
input[strcspn(input, "\n")] = 0;
|
|
if (strcmp(input, "koniec") == 0 ||
|
|
strcmp(input, "exit") == 0 ||
|
|
strcmp(input, "quit") == 0) {
|
|
break;
|
|
}
|
|
if (strlen(input) == 0) {
|
|
continue;
|
|
}
|
|
bool error = false;
|
|
double result = evaluate_expression(input, &error);
|
|
if (error || isnan(result)) {
|
|
printf("Chyba: Neplatny vyraz!\n");
|
|
} else {
|
|
printf("Vysledok: %.2f\n", result);
|
|
}
|
|
}
|
|
|
|
printf("Kalkulacka ukoncena.\n");
|
|
return 0;
|
|
}
|