From afa3571727a7e7c519a5687abe723efcb61f5ab7 Mon Sep 17 00:00:00 2001 From: Peter Sabol Date: Thu, 31 Mar 2022 10:20:05 +0200 Subject: [PATCH] funguje --- du4/program | Bin 7922 -> 7996 bytes du4/program.c | 106 +++++++++++++++++++++++++++++++------------------- 2 files changed, 67 insertions(+), 39 deletions(-) diff --git a/du4/program b/du4/program index bbcaec86418ad32d2ea9e7bf822e447a39384d64..e5fc2da53157021050cef68ee4be71856ade840e 100755 GIT binary patch delta 3626 zcmZu!4Nz3q6~6DWyS&9^f7lg)LUxfw2m}O+)g)L^H*JhW2{ERQRznIDCXAZ+*38&U z7rTp!fPr2n%_JnF)n?MBoi>H4GhHniGME@U!#LBl)X-q3ZFY;v#CBq^iN1d4{e%az zcjoN5=l|#4_ukq6tcicKKgaGqY>{dhW4!}~-?N=|F?QNDa4gSSFEF-s;OATHaVKN( z;}$8-1>xE4ot3Agfj53T_)_xN(Ec|*eqiO*^WXQtItySdqTz>0Is*=vUEdRO=z9yW z8(;;b^Bc}3{BoAGk%Vag8*TI@0xtq&=yaxz36YGvAYau}XDJI{%iR2yP@dUETYY8m zLeVQs@M3Yy(~F8Iz6Z7g!1er=c(t(gnU)sz?fQ-DH|$c!YZ@SAVXtZ` zC7wg{accu#Wm_AWfc)e+MDC6SN3g#b3R>v=;6H)0PmJGD6o@X98u{%G1troUVUNb| zhN^!~EgDy~nJXsXI%!7Gn7XYfx`FEqtIcr5{*F^$YGNs_*aTQ}oY<%uGnFS66Yx&*3+wL45~Q` zmt1GETo~J9eJ{Ap0v#S9ulB?8P4+g0jZ!ZPNiYZtVrRauRd4`Ht7hLj*3yO83M4% z>KQUOgAT0{xA)$${jG@>Z07X>0ShCea5S%Vm9AJju1<>3wH2<|W{9G{RAUHzprV192H>F}{$Tg|h zYvh6y?4z+D-KiO&-{=$a8wKZn?JBu?*W(~+Ngh`-O_MzrEx~>~DT&wqrzpur^sF=atyIiiBX@(weU#!(KG#Wol40g_%N^rv3uf ztHipCSeL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rsum=0; -/* char input[1000]; + /* char input[1000]; char num_str[30] = {0}; float numbers[3]; fgets(input, 999, stdin); @@ -39,7 +37,7 @@ int main(){ */ char* input = calloc(1000, 1); while (1) { - + input = fgets(input, 1000, stdin); if (input == NULL) break; @@ -47,9 +45,9 @@ int main(){ if (input[0] == '\n' || input[0] == EOF || strlen(input) <= 0) break; - float values[3] = {0}; + float values[3] = {0}; char operation = 0; - + int k = 0; int num = strlen(input); for (int i = 0; i < num; i++) { @@ -60,7 +58,7 @@ int main(){ if (isalpha(input[i])) break; - + if (i < strlen(input) && (isdigit(input[i]) || input[i] == '.' || (input[i] == '-' && isdigit(input[i + 1])))) { char temp[100] = {0}; for (int j = 0; i < strlen(input) && (isdigit(input[i]) || input[i] == '.' || input[i] == '-'); j++) { @@ -75,85 +73,115 @@ int main(){ } } - + if (k != 3) { printf("CHYBA\n"); continue; } - if (operation == 0 && values[1] < 0) { operation = '-'; values[1] = abs(values[1]); } - - float result = 0; - - - -//////////////////////////////////////////////// - - /*if((operand == '/') && (number2 == 0)){ + + float result = 0; + + switch (operation) { + case '+': { + result = values[0] + values[1]; + break; + } + case '-': { + result = values[0] - values[1]; + break; + } + case '/': { + result = values[0] / values[1]; + break; + } + case '*': { + result = values[0] * values[1]; + break; + } + default: { + printf("CHYBA\n"); + continue; + } + } + + + char result_string[50]; + sprintf(result_string, "%.2f", result); + result = atof(result_string); + + if (result == values[2]) + printf("OK\n"); + else + printf("ZLE\n"); + } + if((operand == '/') && (number2 == 0)){ printf("Nulou sa nedá deliť"); } if(operand !='+' && operand !='-' && operand !='*' && operand !='/'){ return 1; printf("\n"); } - */ - msum=values[2]; - if(operation=='+'){ - rsum=values[0]+values[1]; + + //msum=values[2]; + if(operand=='+'){ + // rsum=values[0]+values[1]; char rmsum[50]; sprintf(rmsum, "%.2f", msum); msum = atof(rmsum); if(msum==rsum){ - printf("OK\n"); + //printf("OK\n"); } else{ - printf("ZLE\n"); + //printf("ZLE\n"); } //printf("%lf\n",rsum); } - else if(operation=='-'){ - rsum=values[0]-values[1]; + else if(operand=='-'){ + // rsum=values[0]-values[1]; char rmsum[50]; sprintf(rmsum, "%.2f", msum); msum = atof(rmsum); if(msum==rsum){ - printf("OK\n"); + //printf("OK\n"); } else{ - printf("ZLE\n"); + //printf("ZLE\n"); } //printf("%lf\n",rsum); } - else if(operation=='*'){ - rsum=values[0]*values[1]; + else if(operand=='*'){ + // rsum=values[0]*values[1]; char rmsum[50]; sprintf(rmsum, "%.2f", msum); msum = atof(rmsum); if(msum==rsum){ - printf("OK\n"); + //printf("OK\n"); } else{ - printf("ZLE\n"); + //printf("ZLE\n"); } //printf("%lf\n",rsum); } - else if(operation=='/'){ - rsum=values[0]/values[1]; + else if(operand=='/'){ + // rsum=values[0]/values[1]; char rmsum[50]; sprintf(rmsum, "%.2f", msum); msum = atof(rmsum); if(msum==rsum){ - printf("OK\n"); + //printf("OK\n"); } else{ - printf("ZLE\n"); + //printf("ZLE\n"); } //printf("%lf\n",rsum); } - } - } \ No newline at end of file + free(input); + + return 0; +}