usaa21/cv3/program.c

55 lines
2.0 KiB
C
Raw Normal View History

2021-10-21 18:53:21 +00:00
#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() {
2021-10-21 20:03:57 +00:00
struct zasobnik databaza[velkost];
char input[100]= {0};
2021-10-21 20:06:19 +00:00
float number = 0;
2021-10-21 20:03:57 +00:00
int counter = 0;
2021-10-21 18:53:21 +00:00
2021-10-21 20:03:57 +00:00
while(fgets(input, sizeof(input), stdin) && strcmp( input, "\n" ) != 0 ){
number = strtof(input, NULL);
databaza[counter].price = number;
2021-10-21 18:53:21 +00:00
2021-10-21 20:03:57 +00:00
if(input[0] == '+'){
2021-10-21 20:05:25 +00:00
printf("%.2f \n",databaza[counter-2].price);
printf("%.2f %.2f \n",databaza[counter-2].price, databaza[counter-1].price);
2021-10-21 20:03:57 +00:00
databaza[counter-2].price = databaza[counter-2].price + databaza[counter-1].price;
2021-10-21 20:05:25 +00:00
printf("%.2f \n",databaza[counter-2].price);
2021-10-21 20:03:57 +00:00
}
if(input[0] == '-'){
2021-10-21 20:05:25 +00:00
printf("%.2f \n",databaza[counter-2].price);
printf("%.2f %.2f \n",databaza[counter-2].price, databaza[counter-1].price);
2021-10-21 20:03:57 +00:00
databaza[counter-2].price = databaza[counter-2].price - databaza[counter-1].price;
2021-10-21 20:05:25 +00:00
printf("%.2f \n",databaza[counter-2].price);
2021-10-21 20:03:57 +00:00
}
if(input[0] == '/'){
2021-10-21 20:38:45 +00:00
if(databaza[counter-1].price == 0){
2021-10-21 20:37:40 +00:00
printf("division by zero");
return 0;
}
2021-10-21 20:05:25 +00:00
printf("%.2f \n",databaza[counter-2].price);
printf("%.2f %.2f \n",databaza[counter-2].price, databaza[counter-1].price);
2021-10-21 20:03:57 +00:00
databaza[counter-2].price = databaza[counter-2].price / databaza[counter-1].price;
2021-10-21 20:05:25 +00:00
printf("%.2f \n",databaza[counter-2].price);
2021-10-21 20:03:57 +00:00
}
if(input[0] == '*'){
2021-10-21 20:05:25 +00:00
printf("%.2f \n",databaza[counter-2].price);
printf("%.2f %.2f \n",databaza[counter-2].price, databaza[counter-1].price);
2021-10-21 20:03:57 +00:00
databaza[counter-2].price = databaza[counter-2].price * databaza[counter-1].price;
2021-10-21 20:05:25 +00:00
printf("%.2f \n",databaza[counter-2].price);
2021-10-21 20:03:57 +00:00
}
counter++;
}
printf("no input\n");
2021-10-21 18:53:21 +00:00
}