2023-12-04 15:56:21 +01:00
|
|
|
#include "stdio.h"
|
|
|
|
#include "calc.h"
|
2023-12-18 15:36:37 +01:00
|
|
|
|
|
|
|
//#define DOWHILE
|
|
|
|
|
2024-01-22 14:41:15 +01:00
|
|
|
int calc() {
|
2023-12-18 14:54:52 +01:00
|
|
|
char pokracovat = 'a';
|
2024-01-22 14:41:15 +01:00
|
|
|
#ifndef DOWHILE
|
2023-12-18 14:54:52 +01:00
|
|
|
while (pokracovat == 'a') {
|
2024-01-22 14:41:15 +01:00
|
|
|
#endif
|
|
|
|
#ifdef DOWHILE
|
2023-12-18 15:36:37 +01:00
|
|
|
do {
|
2024-01-22 14:41:15 +01:00
|
|
|
#endif
|
2023-12-18 15:36:37 +01:00
|
|
|
|
2023-12-18 14:54:52 +01:00
|
|
|
double a = 0;
|
|
|
|
double b = 0;
|
|
|
|
char operacia = 0;
|
2023-12-18 15:19:55 +01:00
|
|
|
double vysledok;
|
2023-12-18 14:54:52 +01:00
|
|
|
printf("Zadaj prvé číslo:\n");
|
|
|
|
scanf("%lf", &a);
|
|
|
|
printf("Zadaj druhé číslo:\n");
|
|
|
|
scanf("%lf", &b);
|
|
|
|
printf("Zadaj operáciu(+ - * /):\n");
|
|
|
|
scanf(" %c", &operacia);
|
|
|
|
vysledok = a;
|
|
|
|
switch (operacia) {
|
|
|
|
case '+':
|
|
|
|
vysledok += b;
|
|
|
|
break;
|
2023-12-04 15:56:21 +01:00
|
|
|
|
2023-12-18 14:54:52 +01:00
|
|
|
case '-':
|
|
|
|
vysledok -= b;
|
|
|
|
break;
|
2023-12-04 15:56:21 +01:00
|
|
|
|
2023-12-18 14:54:52 +01:00
|
|
|
case '*':
|
|
|
|
vysledok *= b;
|
|
|
|
break;
|
2023-12-04 15:56:21 +01:00
|
|
|
|
2023-12-18 14:54:52 +01:00
|
|
|
case '/':
|
|
|
|
vysledok /= b;
|
|
|
|
break;
|
2023-12-04 15:56:21 +01:00
|
|
|
|
2023-12-18 14:54:52 +01:00
|
|
|
default:
|
2023-12-18 15:36:37 +01:00
|
|
|
printf("Nesprávna operácia.\n");
|
2023-12-18 14:54:52 +01:00
|
|
|
}
|
|
|
|
printf("Vysledok %f %c %f je: %f.\nPrajete si pokračovať(a/n)?\n", a, operacia, b, vysledok);
|
|
|
|
scanf("%s", &pokracovat);
|
2023-12-04 15:56:21 +01:00
|
|
|
}
|
2024-01-22 14:41:15 +01:00
|
|
|
#ifdef DOWHILE
|
2023-12-18 15:36:37 +01:00
|
|
|
while(pokracovat == 'a');
|
2024-01-22 14:41:15 +01:00
|
|
|
#endif
|
2023-12-04 15:56:21 +01:00
|
|
|
return 0;
|
2023-12-18 14:54:52 +01:00
|
|
|
|
2023-12-04 15:56:21 +01:00
|
|
|
}
|