Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- typedef enum cloudiness { sunny, patly, cloudy, rain, heavy_rain } cloudiness;
- typedef struct comp_data {
- enum cloudiness clouds;
- int temp,
- price_glass_buy,
- price_flyer;
- } comp_data;
- typedef struct user_data {
- int num_glass,
- num_flyer,
- price_glass_sell;
- } user_data;
- comp_data static g_compData = { 0,0,0,0 };
- user_data static g_userData = { 0,0,0 };
- int g_credit = 300;
- void processing();
- void сompData_calculation();
- void output_сompData_calculation();
- void input();
- int getInt(int* pn);
- int input_check_money();
- void sell_info();
- int glass_sold_num_calculation();
- int glass_demand_calculation();
- void end_day();
- int credit_calculation();
- void extra_credit();
- void end_game();
- int main() {
- const int days_num = 21;
- for (int i = 0; i < days_num; i++) {
- processing();
- }
- end_game();
- }
- void processing() {
- //Расчёт первоначальных данных
- сompData_calculation();
- //Вывод первоначальных данных
- output_сompData_calculation();
- //Считывание пользовательских данных
- input();
- //Расчёт продаж
- sell_info();
- //Расчёт баланса в завершении дня
- end_day();
- }
- void сompData_calculation() {
- g_compData.clouds = rand() * time(NULL) % 2; //ранд бывает отрицательным
- g_compData.temp = rand() * time(NULL) % 20 + 10;
- g_compData.price_flyer = rand() * time(NULL) % 20 + 10;
- g_compData.price_glass_buy = rand() * time(NULL) % 10 + 5;
- }
- void output_сompData_calculation() {
- printf("\nToday weather cast: clouds: %d\nTemperature: %d\nPrice for 1 flyer: %d\nPrice 1 glass: %d",
- g_compData.clouds, g_compData.temp, g_compData.price_flyer, g_compData.price_glass_buy); //отдельный вывод облачности в строку, а не цифрой
- }
- void input() {
- puts("\nPlease, write the number of glasses :");
- int error_input = 0;
- while (!error_input)
- error_input = getInt(&g_userData.num_glass);
- error_input = 0;
- while (!error_input)
- error_input = input_check_money();//тут оно умирало в цикле, т.к. error_input не менялось
- puts("\nNumber of flyers :");
- error_input = 0;
- while (!error_input)
- error_input = getInt(&g_userData.num_flyer);
- error_input = 0;
- while (!error_input)
- error_input = input_check_money();
- puts("\n And price:");
- error_input = 0;
- while (!error_input)
- error_input = getInt(&g_userData.price_glass_sell);
- }
- int getInt(int* pn) {
- const char *errmsg = "";
- int n;
- do {
- puts(errmsg);
- errmsg = "Repeat input";
- n = scanf_s("%d", pn);
- if (n < 0) // добавить проверку на отрицательность
- return 0;
- scanf_s("%*[^\n]");//Что это?
- scanf_s("%*c");
- } while (n == 0);
- return 1;
- }
- int input_check_money() {
- if (g_credit >= g_compData.price_flyer * g_userData.num_flyer+ g_compData.price_glass_buy * g_userData.num_glass)
- return 1;
- else
- return 0;
- }
- void sell_info() {
- printf("\nYou have sold %d glasses and have earned %d$",
- glass_sold_num_calculation(), glass_sold_num_calculation()* g_userData.price_glass_sell); //ф-ия считается три раза (ещё один в credit_calc)
- }
- int glass_sold_num_calculation() {
- return round(glass_demand_calculation()*(0.5+0.05* g_userData.num_flyer));
- }
- int glass_demand_calculation() {
- return g_userData.num_glass * (4 - g_compData.clouds) / (30 - g_compData.temp);
- }
- void end_day() {
- if (!credit_calculation())
- extra_credit();
- }
- int credit_calculation() {
- g_credit = g_credit
- - g_compData.price_glass_buy * g_userData.num_glass
- + glass_sold_num_calculation() * g_userData.price_glass_sell;
- if (g_credit > 0)
- return 1;
- else
- return 0;
- }
- void extra_credit() {
- return 0;
- } //дописать
- void end_game() {
- return 0;
- } //дописать
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement