usaa21/cv3/program.c
Peter Petrek a8a9f80153 /0v3
2021-10-21 22:39:42 +02:00

57 lines
2.2 KiB
C

#include <stdio.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define velkost 10
struct zasobnik {
float price;
};
int main() {
struct zasobnik databaza[velkost];
char input[100]= {0};
float number = 0;
int counter = 0;
while(fgets(input, sizeof(input), stdin) && strcmp( input, "\n" ) != 0 ){
number = strtof(input, NULL);
databaza[counter].price = number;
if(input[0] == '+'){
printf("%.2f \n",databaza[counter-2].price);
printf("%.2f %.2f \n",databaza[counter-2].price, databaza[counter-1].price);
databaza[counter-2].price = databaza[counter-2].price + databaza[counter-1].price;
printf("%.2f \n",databaza[counter-2].price);
}
if(input[0] == '-'){
printf("%.2f \n",databaza[counter-2].price);
printf("%.2f %.2f \n",databaza[counter-2].price, databaza[counter-1].price);
databaza[counter-2].price = databaza[counter-2].price - databaza[counter-1].price;
printf("%.2f \n",databaza[counter-2].price);
}
if(input[0] == '/'){
if(databaza[counter-1].price == 0){
printf("%.2f \n",databaza[counter-2].price);
printf("%.2f %.2f \n",databaza[counter-2].price, databaza[counter-1].price);
printf("division by zero");
return 0;
}
printf("%.2f \n",databaza[counter-2].price);
printf("%.2f %.2f \n",databaza[counter-2].price, databaza[counter-1].price);
databaza[counter-2].price = databaza[counter-2].price / databaza[counter-1].price;
printf("%.2f \n",databaza[counter-2].price);
}
if(input[0] == '*'){
printf("%.2f \n",databaza[counter-2].price);
printf("%.2f %.2f \n",databaza[counter-2].price, databaza[counter-1].price);
databaza[counter-2].price = databaza[counter-2].price * databaza[counter-1].price;
printf("%.2f \n",databaza[counter-2].price);
}
counter++;
}
printf("no input\n");
}