This commit is contained in:
Peter Sabol 2022-03-31 10:20:05 +02:00
parent 350dd19960
commit afa3571727
2 changed files with 67 additions and 39 deletions

Binary file not shown.

View File

@ -5,9 +5,7 @@
#include <ctype.h> #include <ctype.h>
int main() { int main() {
int i,j; int i,j;
double number1, number2, summary,msum; double number1, number2, summary,msum;
char operand, equ; char operand, equ;
@ -81,7 +79,6 @@ int main(){
continue; continue;
} }
if (operation == 0 && values[1] < 0) { if (operation == 0 && values[1] < 0) {
operation = '-'; operation = '-';
values[1] = abs(values[1]); values[1] = abs(values[1]);
@ -90,70 +87,101 @@ int main(){
float result = 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((operand == '/') && (number2 == 0)){ if (result == values[2])
printf("OK\n");
else
printf("ZLE\n");
}
if((operand == '/') && (number2 == 0)){
printf("Nulou sa nedá deli<6C>"); printf("Nulou sa nedá deli<6C>");
} }
if(operand !='+' && operand !='-' && operand !='*' && operand !='/'){ if(operand !='+' && operand !='-' && operand !='*' && operand !='/'){
return 1; return 1;
printf("\n"); printf("\n");
} }
*/
msum=values[2]; //msum=values[2];
if(operation=='+'){ if(operand=='+'){
rsum=values[0]+values[1]; // rsum=values[0]+values[1];
char rmsum[50]; char rmsum[50];
sprintf(rmsum, "%.2f", msum); sprintf(rmsum, "%.2f", msum);
msum = atof(rmsum); msum = atof(rmsum);
if(msum==rsum){ if(msum==rsum){
printf("OK\n"); //printf("OK\n");
} }
else{ else{
printf("ZLE\n"); //printf("ZLE\n");
} }
//printf("%lf\n",rsum); //printf("%lf\n",rsum);
} }
else if(operation=='-'){ else if(operand=='-'){
rsum=values[0]-values[1]; // rsum=values[0]-values[1];
char rmsum[50]; char rmsum[50];
sprintf(rmsum, "%.2f", msum); sprintf(rmsum, "%.2f", msum);
msum = atof(rmsum); msum = atof(rmsum);
if(msum==rsum){ if(msum==rsum){
printf("OK\n"); //printf("OK\n");
} }
else{ else{
printf("ZLE\n"); //printf("ZLE\n");
} }
//printf("%lf\n",rsum); //printf("%lf\n",rsum);
} }
else if(operation=='*'){ else if(operand=='*'){
rsum=values[0]*values[1]; // rsum=values[0]*values[1];
char rmsum[50]; char rmsum[50];
sprintf(rmsum, "%.2f", msum); sprintf(rmsum, "%.2f", msum);
msum = atof(rmsum); msum = atof(rmsum);
if(msum==rsum){ if(msum==rsum){
printf("OK\n"); //printf("OK\n");
} }
else{ else{
printf("ZLE\n"); //printf("ZLE\n");
} }
//printf("%lf\n",rsum); //printf("%lf\n",rsum);
} }
else if(operation=='/'){ else if(operand=='/'){
rsum=values[0]/values[1]; // rsum=values[0]/values[1];
char rmsum[50]; char rmsum[50];
sprintf(rmsum, "%.2f", msum); sprintf(rmsum, "%.2f", msum);
msum = atof(rmsum); msum = atof(rmsum);
if(msum==rsum){ if(msum==rsum){
printf("OK\n"); //printf("OK\n");
} }
else{ else{
printf("ZLE\n"); //printf("ZLE\n");
} }
//printf("%lf\n",rsum); //printf("%lf\n",rsum);
} }
} free(input);
return 0;
} }