This commit is contained in:
Peter Sabol 2022-03-31 10:24:10 +02:00
parent 73a040fa6b
commit 3db3c1b900
2 changed files with 48 additions and 76 deletions

Binary file not shown.

View File

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