Изменил(а) на 'cv3/program.c'

This commit is contained in:
Oleksandr Hryshchenko 2021-10-22 11:11:04 +00:00
parent 3034a490df
commit 71bc6751f4

View File

@ -33,25 +33,25 @@ bool calculatorLogic(char buffer[SIZE][SIZE]){
switch(buffer[currentlyInBuffer][0]){ switch(buffer[currentlyInBuffer][0]){
case '+': case '+':
temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) + atof(buffer[currentlyInBuffer-2]))*100)/100; temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) + atof(buffer[currentlyInBuffer-1]))*100)/100;
break; break;
case '-': case '-':
temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) - atof(buffer[currentlyInBuffer-2]))*100)/100; temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) - atof(buffer[currentlyInBuffer-1]))*100)/100;
break; break;
case '*': case '*':
temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) * atof(buffer[currentlyInBuffer-2]))*100)/100; temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) * atof(buffer[currentlyInBuffer-1]))*100)/100;
break; break;
case '/': case '/':
if(atof(buffer[currentlyInBuffer-2]) == 0.0) if(atof(buffer[currentlyInBuffer-1]) == 0.0)
printf("division by zero\n"); printf("division by zero\n");
else else
temporaryDecimal = round((atof(buffer[currentlyInBuffer-1]) / atof(buffer[currentlyInBuffer-2]))*100)/100; temporaryDecimal = round((atof(buffer[currentlyInBuffer-2]) / atof(buffer[currentlyInBuffer-1]))*100)/100;
} }
for(int i = currentlyInBuffer-3; currentlyInBuffer > i; currentlyInBuffer--) for(int i = currentlyInBuffer-3; currentlyInBuffer > i; currentlyInBuffer--)
memset(buffer[currentlyInBuffer], SIZE, '\0'); memset(buffer[currentlyInBuffer], SIZE, '\0');
gcvt(temporaryDecimal, 10, buffer[currentlyInBuffer]); gcvt(temporaryDecimal, 10, buffer[currentlyInBuffer++]);
for(int i = 0; i <= currentlyInBuffer; i++){ for(int i = 0; i <= currentlyInBuffer; i++){
if(i == currentlyInBuffer) if(i == currentlyInBuffer)
@ -65,9 +65,9 @@ bool calculatorLogic(char buffer[SIZE][SIZE]){
else{ else{
printf("bad input\n"); printf("bad input\n");
} }
} }
int main() { int main() {
char buffer[SIZE][SIZE]; char buffer[SIZE][SIZE];
for(int i = 0; i < SIZE; i++) for(int i = 0; i < SIZE; i++)
memset(buffer[i], '\0', SIZE); memset(buffer[i], '\0', SIZE);
@ -80,5 +80,4 @@ bool calculatorLogic(char buffer[SIZE][SIZE]){
printf("no input\n"); printf("no input\n");
return 0; return 0;
} }