From e9e27bcf3b980570d50176c42504426abc064d0c Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 1 Oct 2021 17:22:32 +0000 Subject: [PATCH 01/10] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D0=BD=D0=B0=20'cv2/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv2/program.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/cv2/program.c b/cv2/program.c index 53c5fdf..ed22110 100644 --- a/cv2/program.c +++ b/cv2/program.c @@ -1 +1,110 @@ #include +#include +#include +#include + +struct dish{ + char name[100]; + float price; +}; + +int comparator (const void * p1, const void * p2){ + return (*(int*)p1 - *(int*)p2); +} + +void getOrder(struct dish dishesList[100], int dishesNumber, int* result){ + float allPrises[dishesNumber]; + float ascendingPrises[dishesNumber]; + int* order = calloc(dishesNumber, sizeof(int)); + int counter = 0; + float temp; + + for(int i = 0; i < dishesNumber; i++){ + allPrises[i] = dishesList[i].price; + ascendingPrises[i] = allPrises[i]; + } + + qsort(ascendingPrises, dishesNumber, sizeof(int), comparator); + + for(int i = 0; i < dishesNumber; i++){ + for(int j = 0; j < dishesNumber; j++){ + STEP: + if(ascendingPrises[i] == allPrises[j]){ + for(int y = 0; y < counter; y++){ + if(order[y] == j){ + j++; + goto STEP; + } + } + order[counter] = j; + counter++; + break; + } + } + } + + memcpy(result, order, dishesNumber * sizeof(int)); +} + +void getAlphabetOrder(int* order, struct dish dishesList[100], int dishesNumber){ + int* result = calloc(dishesNumber, sizeof(int)); + int counter = 0; + int temp; + + for(int i = 0; i < dishesNumber; i++){ + for(int j = i; j < dishesNumber; j++){ + if(dishesList[order[i]].price == dishesList[order[j]].price){ + if(dishesList[order[i]].name[0] < dishesList[order[j]].name[0]){ + break; + } + else if(dishesList[order[i]].name[0] == dishesList[order[j]].name[0]){ + if(dishesList[order[i]].name[1] < dishesList[order[j]].name[1]){ + break; + } + else{ + temp = order[i]; + order[i] = order[j]; + order[j] = temp; + } + } + else{ + temp = order[i]; + order[i] = order[j]; + order[j] = temp; + } + } + } + result[counter] = order[i]; + counter++; + } + + memcpy(order, result, dishesNumber * sizeof(int)); +} + +int main(){ + struct dish dishesList[100]; + int i = 0; + int finalCounter = 0; + + for(i = 0; fgets(dishesList[i].name, 100, stdin); i++){ + finalCounter++; + if(dishesList[i].name[0] == '\n' || dishesList[i].name[0] == '\0') finalCounter--; + scanf("%f", &dishesList[i].price); + if(dishesList[i].price == 0.0){ + finalCounter--; + break; + } + getchar(); + } + + int* printOrder = calloc(finalCounter, sizeof(int)); + getOrder(dishesList, finalCounter, printOrder); + getAlphabetOrder(printOrder, dishesList, finalCounter); + + for(int j = 0; j < finalCounter; j++){ + printf("%s", dishesList[printOrder[j]].name); + printf("%f\n", dishesList[printOrder[j]].price); + } + + return 0; +} \ No newline at end of file From 03aedc72b7484e8725b08a5db35298c8c4079984 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Tue, 19 Oct 2021 10:04:24 +0000 Subject: [PATCH 02/10] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D0=BD=D0=B0=20'cv2/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv2/program.c | 55 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/cv2/program.c b/cv2/program.c index ed22110..11d95f4 100644 --- a/cv2/program.c +++ b/cv2/program.c @@ -6,27 +6,26 @@ struct dish{ char name[100]; float price; -}; +}; // блюда -- название и цена int comparator (const void * p1, const void * p2){ return (*(int*)p1 - *(int*)p2); -} +} // сравнитель для сортировки -void getOrder(struct dish dishesList[100], int dishesNumber, int* result){ - float allPrises[dishesNumber]; - float ascendingPrises[dishesNumber]; - int* order = calloc(dishesNumber, sizeof(int)); - int counter = 0; - float temp; +void getOrder(struct dish dishesList[100], int dishesNumber, int* result){ //сортиовка по ценам + float allPrises[dishesNumber]; //все цены + float ascendingPrises[dishesNumber]; // для сортировки в будущем + int* order = calloc(dishesNumber, sizeof(int)); //порядок возрастающих элементов в масиве + int counter = 0; //счетчик for(int i = 0; i < dishesNumber; i++){ allPrises[i] = dishesList[i].price; ascendingPrises[i] = allPrises[i]; } - qsort(ascendingPrises, dishesNumber, sizeof(int), comparator); + qsort(ascendingPrises, dishesNumber, sizeof(int), comparator); //процеес сортировки - for(int i = 0; i < dishesNumber; i++){ + for(int i = 0; i < dishesNumber; i++){ //запись порядка элемента в основном массиве for(int j = 0; j < dishesNumber; j++){ STEP: if(ascendingPrises[i] == allPrises[j]){ @@ -43,65 +42,65 @@ void getOrder(struct dish dishesList[100], int dishesNumber, int* result){ } } - memcpy(result, order, dishesNumber * sizeof(int)); + memcpy(result, order, dishesNumber * sizeof(int)); //копирование одного в другой } -void getAlphabetOrder(int* order, struct dish dishesList[100], int dishesNumber){ +void getAlphabetOrder(int* order, struct dish dishesList[100], int dishesNumber){ //сорторвка по алфавиту int* result = calloc(dishesNumber, sizeof(int)); int counter = 0; int temp; for(int i = 0; i < dishesNumber; i++){ - for(int j = i; j < dishesNumber; j++){ - if(dishesList[order[i]].price == dishesList[order[j]].price){ - if(dishesList[order[i]].name[0] < dishesList[order[j]].name[0]){ + for(int j = i; j < dishesNumber; j++){ //чтение масивов их сравнение + if(dishesList[order[i]].price == dishesList[order[j]].price){ //сравнение если цены совпадают + if(dishesList[order[i]].name[0] < dishesList[order[j]].name[0]){ // если цены сопали но уже в порядке алфавита break; } - else if(dishesList[order[i]].name[0] == dishesList[order[j]].name[0]){ + else if(dishesList[order[i]].name[0] == dishesList[order[j]].name[0]){ //если цены совпали но первые буквы одиннаковые if(dishesList[order[i]].name[1] < dishesList[order[j]].name[1]){ break; } - else{ + else{ temp = order[i]; order[i] = order[j]; order[j] = temp; } } - else{ + else{ //цены совпали но не в порядке алфавита temp = order[i]; order[i] = order[j]; order[j] = temp; } } } - result[counter] = order[i]; + result[counter] = order[i]; //запись сортирвки counter++; } - memcpy(order, result, dishesNumber * sizeof(int)); + memcpy(order, result, dishesNumber * sizeof(int)); //запись результата в main } int main(){ - struct dish dishesList[100]; + struct dish dishesList[100]; //список блюдд int i = 0; - int finalCounter = 0; + int finalCounter = 0; //конечный счётчик колличества блюд - for(i = 0; fgets(dishesList[i].name, 100, stdin); i++){ + for(i = 0; fgets(dishesList[i].name, 100, stdin); i++){ // запись блюд с ввода finalCounter++; - if(dishesList[i].name[0] == '\n' || dishesList[i].name[0] == '\0') finalCounter--; + if(dishesList[i].name[0] == '\n' || dishesList[i].name[0] == '\0') finalCounter--; //если название пустое scanf("%f", &dishesList[i].price); - if(dishesList[i].price == 0.0){ + if(dishesList[i].price == 0.0){ //если цены нету finalCounter--; break; } - getchar(); + getchar(); //убирает перенос строки с ввода } - int* printOrder = calloc(finalCounter, sizeof(int)); + int* printOrder = calloc(finalCounter, sizeof(int)); //полная запись всего результата getOrder(dishesList, finalCounter, printOrder); getAlphabetOrder(printOrder, dishesList, finalCounter); - for(int j = 0; j < finalCounter; j++){ + for(int j = 0; j < finalCounter; j++){ //вывод printf("%s", dishesList[printOrder[j]].name); printf("%f\n", dishesList[printOrder[j]].price); } From 3034a490dfa6058469fb6499143d657f54bd3ae3 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 22 Oct 2021 11:02:29 +0000 Subject: [PATCH 03/10] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D0=BD=D0=B0=20'cv3/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/cv3/program.c b/cv3/program.c index 53c5fdf..2356201 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -1 +1,84 @@ #include +#include +#include +#include +#include +#include + +#define SIZE 50 + +int currentlyInBuffer = 0; + +bool calculatorLogic(char buffer[SIZE][SIZE]){ + if(isdigit(buffer[currentlyInBuffer][0])){ + if(currentlyInBuffer == 9) { + printf("full stack\n"); + return false; + } + for(int i = 0; i <= currentlyInBuffer; i++){ + if(i == currentlyInBuffer) + printf("%0.2f \n", roundf(atof(buffer[i])*100)/100); + else + printf("%0.2f ", roundf(atof(buffer[i])*100)/100); + } + return true; + } + else if(strchr("+-/*", buffer[currentlyInBuffer][0]) != NULL){ + if(currentlyInBuffer < 2){ + printf("not enough operands\n"); + return false; + } + + double temporaryDecimal = 0; + + switch(buffer[currentlyInBuffer][0]){ + case '+': + temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) + atof(buffer[currentlyInBuffer-2]))*100)/100; + break; + case '-': + temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) - atof(buffer[currentlyInBuffer-2]))*100)/100; + break; + case '*': + temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) * atof(buffer[currentlyInBuffer-2]))*100)/100; + break; + case '/': + if(atof(buffer[currentlyInBuffer-2]) == 0.0) + printf("division by zero\n"); + else + temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) / atof(buffer[currentlyInBuffer-2]))*100)/100; + } + + for(int i = currentlyInBuffer-3; currentlyInBuffer > i; currentlyInBuffer--) + memset(buffer[currentlyInBuffer], SIZE, '\0'); + + gcvt(temporaryDecimal, 10, buffer[currentlyInBuffer]); + + for(int i = 0; i <= currentlyInBuffer; i++){ + if(i == currentlyInBuffer) + printf("%0.2f \n", roundf(atof(buffer[i]) * 100) / 100); + else + printf("%0.2f ", roundf(atof(buffer[i]) * 100) / 100); + } + + return true; + } + else{ + printf("bad input\n"); + } + } + + int main() { + char buffer[SIZE][SIZE]; + for(int i = 0; i < SIZE; i++) + memset(buffer[i], '\0', SIZE); + + for(; fgets(buffer[currentlyInBuffer], SIZE, stdin); currentlyInBuffer++) + if(!calculatorLogic(buffer)) + return 0; + + if(buffer[currentlyInBuffer][0] == '\0') + printf("no input\n"); + + return 0; + } + \ No newline at end of file From 71bc6751f44ca80389b69bbecfe0b53fd289133f Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 22 Oct 2021 11:11:04 +0000 Subject: [PATCH 04/10] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D0=BD=D0=B0=20'cv3/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 121 +++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 2356201..80cc3da 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -11,74 +11,73 @@ int currentlyInBuffer = 0; bool calculatorLogic(char buffer[SIZE][SIZE]){ if(isdigit(buffer[currentlyInBuffer][0])){ - if(currentlyInBuffer == 9) { - printf("full stack\n"); - return false; - } - for(int i = 0; i <= currentlyInBuffer; i++){ - if(i == currentlyInBuffer) - printf("%0.2f \n", roundf(atof(buffer[i])*100)/100); - else - printf("%0.2f ", roundf(atof(buffer[i])*100)/100); - } - return true; - } - else if(strchr("+-/*", buffer[currentlyInBuffer][0]) != NULL){ - if(currentlyInBuffer < 2){ - printf("not enough operands\n"); - return false; - } + if(currentlyInBuffer == 9) { + printf("full stack\n"); + return false; + } + for(int i = 0; i <= currentlyInBuffer; i++){ + if(i == currentlyInBuffer) + printf("%0.2f \n", roundf(atof(buffer[i])*100)/100); + else + printf("%0.2f ", roundf(atof(buffer[i])*100)/100); + } + return true; + } + else if(strchr("+-/*", buffer[currentlyInBuffer][0]) != NULL){ + if(currentlyInBuffer < 2){ + printf("not enough operands\n"); + return false; + } - double temporaryDecimal = 0; + double temporaryDecimal = 0; - switch(buffer[currentlyInBuffer][0]){ - case '+': - temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) + atof(buffer[currentlyInBuffer-2]))*100)/100; - break; - case '-': - temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) - atof(buffer[currentlyInBuffer-2]))*100)/100; - break; - case '*': - temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) * atof(buffer[currentlyInBuffer-2]))*100)/100; - break; - case '/': - if(atof(buffer[currentlyInBuffer-2]) == 0.0) - printf("division by zero\n"); - else - temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) / atof(buffer[currentlyInBuffer-2]))*100)/100; - } + switch(buffer[currentlyInBuffer][0]){ + case '+': + temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) + atof(buffer[currentlyInBuffer-1]))*100)/100; + break; + case '-': + temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) - atof(buffer[currentlyInBuffer-1]))*100)/100; + break; + case '*': + temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) * atof(buffer[currentlyInBuffer-1]))*100)/100; + break; + case '/': + if(atof(buffer[currentlyInBuffer-1]) == 0.0) + printf("division by zero\n"); + else + temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) / atof(buffer[currentlyInBuffer-1]))*100)/100; + } - for(int i = currentlyInBuffer-3; currentlyInBuffer > i; currentlyInBuffer--) - memset(buffer[currentlyInBuffer], SIZE, '\0'); + for(int i = currentlyInBuffer-3; currentlyInBuffer > i; currentlyInBuffer--) + memset(buffer[currentlyInBuffer], SIZE, '\0'); - gcvt(temporaryDecimal, 10, buffer[currentlyInBuffer]); + gcvt(temporaryDecimal, 10, buffer[currentlyInBuffer++]); - for(int i = 0; i <= currentlyInBuffer; i++){ - if(i == currentlyInBuffer) - printf("%0.2f \n", roundf(atof(buffer[i]) * 100) / 100); - else - printf("%0.2f ", roundf(atof(buffer[i]) * 100) / 100); - } + for(int i = 0; i <= currentlyInBuffer; i++){ + if(i == currentlyInBuffer) + printf("%0.2f \n", roundf(atof(buffer[i]) * 100) / 100); + else + printf("%0.2f ", roundf(atof(buffer[i]) * 100) / 100); + } - return true; - } - else{ - printf("bad input\n"); - } - } + return true; + } + else{ + printf("bad input\n"); + } +} - int main() { - char buffer[SIZE][SIZE]; - for(int i = 0; i < SIZE; i++) - memset(buffer[i], '\0', SIZE); +int main() { + char buffer[SIZE][SIZE]; + for(int i = 0; i < SIZE; i++) + memset(buffer[i], '\0', SIZE); - for(; fgets(buffer[currentlyInBuffer], SIZE, stdin); currentlyInBuffer++) - if(!calculatorLogic(buffer)) - return 0; + for(; fgets(buffer[currentlyInBuffer], SIZE, stdin); currentlyInBuffer++) + if(!calculatorLogic(buffer)) + return 0; - if(buffer[currentlyInBuffer][0] == '\0') - printf("no input\n"); + if(buffer[currentlyInBuffer][0] == '\0') + printf("no input\n"); - return 0; - } - \ No newline at end of file + return 0; +} \ No newline at end of file From 93c9fc3f3a3bbd2f856208a8e87c95ce9cf608ae Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 22 Oct 2021 11:12:46 +0000 Subject: [PATCH 05/10] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D0=BD=D0=B0=20'cv3/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cv3/program.c b/cv3/program.c index 80cc3da..23ac35d 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -80,4 +80,4 @@ int main() { printf("no input\n"); return 0; -} \ No newline at end of file +} From e6c2f23cc6f9d3e15ffee34fb3cec6ba1ad58196 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 22 Oct 2021 11:37:46 +0000 Subject: [PATCH 06/10] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D0=BD=D0=B0=20'cv3/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 23ac35d..1c5748f 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -48,13 +48,13 @@ bool calculatorLogic(char buffer[SIZE][SIZE]){ temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) / atof(buffer[currentlyInBuffer-1]))*100)/100; } - for(int i = currentlyInBuffer-3; currentlyInBuffer > i; currentlyInBuffer--) - memset(buffer[currentlyInBuffer], SIZE, '\0'); + for(int i = currentlyInBuffer-2; currentlyInBuffer > i; currentlyInBuffer--) + memset(buffer[currentlyInBuffer], '\0', SIZE); gcvt(temporaryDecimal, 10, buffer[currentlyInBuffer++]); - for(int i = 0; i <= currentlyInBuffer; i++){ - if(i == currentlyInBuffer) + for(int i = 0; i < currentlyInBuffer; i++){ + if(i == currentlyInBuffer-1) printf("%0.2f \n", roundf(atof(buffer[i]) * 100) / 100); else printf("%0.2f ", roundf(atof(buffer[i]) * 100) / 100); @@ -64,6 +64,7 @@ bool calculatorLogic(char buffer[SIZE][SIZE]){ } else{ printf("bad input\n"); + return false; } } @@ -80,4 +81,4 @@ int main() { printf("no input\n"); return 0; -} +} \ No newline at end of file From 3abd673a7dbe542b77619f280baea04a41793d36 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 22 Oct 2021 11:53:40 +0000 Subject: [PATCH 07/10] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D0=BD=D0=B0=20'cv3/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cv3/program.c b/cv3/program.c index 1c5748f..aee9825 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -42,8 +42,10 @@ bool calculatorLogic(char buffer[SIZE][SIZE]){ temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) * atof(buffer[currentlyInBuffer-1]))*100)/100; break; case '/': - if(atof(buffer[currentlyInBuffer-1]) == 0.0) + if(atof(buffer[currentlyInBuffer-1]) == 0.0) { printf("division by zero\n"); + return false; + } else temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) / atof(buffer[currentlyInBuffer-1]))*100)/100; } From 054ef15374406f64c27af4a13025cf1df69150b3 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 22 Oct 2021 11:58:39 +0000 Subject: [PATCH 08/10] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D0=BD=D0=B0=20'cv3/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index aee9825..0ee4298 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -53,10 +53,10 @@ bool calculatorLogic(char buffer[SIZE][SIZE]){ for(int i = currentlyInBuffer-2; currentlyInBuffer > i; currentlyInBuffer--) memset(buffer[currentlyInBuffer], '\0', SIZE); - gcvt(temporaryDecimal, 10, buffer[currentlyInBuffer++]); + gcvt(temporaryDecimal, 10, buffer[currentlyInBuffer]); - for(int i = 0; i < currentlyInBuffer; i++){ - if(i == currentlyInBuffer-1) + for(int i = 0; i <= currentlyInBuffer; i++){ + if(i == currentlyInBuffer) printf("%0.2f \n", roundf(atof(buffer[i]) * 100) / 100); else printf("%0.2f ", roundf(atof(buffer[i]) * 100) / 100); From c388fee42434d9ec3e9ef290f6acfef6e1a84b0a Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 22 Oct 2021 12:09:25 +0000 Subject: [PATCH 09/10] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D0=BD=D0=B0=20'cv3/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 0ee4298..ee0b55a 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -33,13 +33,13 @@ bool calculatorLogic(char buffer[SIZE][SIZE]){ switch(buffer[currentlyInBuffer][0]){ case '+': - temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) + atof(buffer[currentlyInBuffer-1]))*100)/100; + temporaryDecimal = round(atof(buffer[currentlyInBuffer-2])*100)/100 + round(atof(buffer[currentlyInBuffer-1])*100)/100; break; case '-': - temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) - atof(buffer[currentlyInBuffer-1]))*100)/100; + temporaryDecimal = round(atof(buffer[currentlyInBuffer-2])*100)/100 - round(atof(buffer[currentlyInBuffer-1])*100)/100; break; case '*': - temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) * atof(buffer[currentlyInBuffer-1]))*100)/100; + temporaryDecimal = round(atof(buffer[currentlyInBuffer-2])*100)/100 * round(atof(buffer[currentlyInBuffer-1])*100)/100; break; case '/': if(atof(buffer[currentlyInBuffer-1]) == 0.0) { @@ -47,7 +47,7 @@ bool calculatorLogic(char buffer[SIZE][SIZE]){ return false; } else - temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) / atof(buffer[currentlyInBuffer-1]))*100)/100; + temporaryDecimal = round(atof(buffer[currentlyInBuffer-2])*100)/100 / round(atof(buffer[currentlyInBuffer-1])*100)/100; } for(int i = currentlyInBuffer-2; currentlyInBuffer > i; currentlyInBuffer--) From 4c98f69b4ddc69a1a8afad98899d692228dc1269 Mon Sep 17 00:00:00 2001 From: Oleksandr Hryshchenko Date: Fri, 22 Oct 2021 12:15:27 +0000 Subject: [PATCH 10/10] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D0=BD=D0=B0=20'cv3/program.c'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv3/program.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index ee0b55a..cfa8f82 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -33,13 +33,13 @@ bool calculatorLogic(char buffer[SIZE][SIZE]){ switch(buffer[currentlyInBuffer][0]){ case '+': - temporaryDecimal = round(atof(buffer[currentlyInBuffer-2])*100)/100 + round(atof(buffer[currentlyInBuffer-1])*100)/100; + temporaryDecimal = (double)(round(atof(buffer[currentlyInBuffer-2])*100)/100) + (double)(round(atof(buffer[currentlyInBuffer-1])*100)/100); break; case '-': - temporaryDecimal = round(atof(buffer[currentlyInBuffer-2])*100)/100 - round(atof(buffer[currentlyInBuffer-1])*100)/100; + temporaryDecimal = (double)(round(atof(buffer[currentlyInBuffer-2])*100)/100) - (double)(round(atof(buffer[currentlyInBuffer-1])*100)/100); break; case '*': - temporaryDecimal = round(atof(buffer[currentlyInBuffer-2])*100)/100 * round(atof(buffer[currentlyInBuffer-1])*100)/100; + temporaryDecimal = (double)(round(atof(buffer[currentlyInBuffer-2])*100)/100) * (double)(round(atof(buffer[currentlyInBuffer-1])*100)/100); break; case '/': if(atof(buffer[currentlyInBuffer-1]) == 0.0) { @@ -47,7 +47,7 @@ bool calculatorLogic(char buffer[SIZE][SIZE]){ return false; } else - temporaryDecimal = round(atof(buffer[currentlyInBuffer-2])*100)/100 / round(atof(buffer[currentlyInBuffer-1])*100)/100; + temporaryDecimal = (double)(round(atof(buffer[currentlyInBuffer-2])*100)/100) / (double)(round(atof(buffer[currentlyInBuffer-1])*100)/100); } for(int i = currentlyInBuffer-2; currentlyInBuffer > i; currentlyInBuffer--)