From 6170be73947c69e042b8b49acc12e1e0484734a5 Mon Sep 17 00:00:00 2001 From: Yevhen Kozirovskyi Date: Thu, 3 Oct 2024 11:08:00 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20cv1/program.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv1/program.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/cv1/program.c b/cv1/program.c index 62560db..720d0ce 100644 --- a/cv1/program.c +++ b/cv1/program.c @@ -8,7 +8,6 @@ void decode(char *text) { for (int i = 0; text[i] != '\0'; i++) { - switch (text[i]) { case '0': text[i] = 'o'; break; case '1': text[i] = 'i'; break; @@ -21,39 +20,43 @@ void decode(char *text) { case '8': text[i] = 'b'; break; case '9': text[i] = 'q'; break; } - text[i] = tolower(text[i]); + text[i] = tolower(text[i]); } } int main() { char slovo[MAX_LENGTH]; char dish_name[MAX_LENGTH]; - char price[MAX_LENGTH]; - int count = 0; - + float price[MAX_DISHES]; // Use float array for prices + int count = 0; printf("Zadaj hladanu surovinu:\n"); fgets(slovo, MAX_LENGTH, stdin); - slovo[strcspn(slovo, "\n")] = 0; - decode(slovo); + slovo[strcspn(slovo, "\n")] = 0; + decode(slovo); printf("Zadaj jedalny listok:\n"); while (1) { if (fgets(dish_name, MAX_LENGTH, stdin) == NULL || strcmp(dish_name, "\n") == 0) { - break; + break; } dish_name[strcspn(dish_name, "\n")] = 0; - // Načítanie ceny jedla - if (fgets(price, MAX_LENGTH, stdin) == NULL || strcmp(price, "\n") == 0) { - break; + + // Read the price as a float + if (scanf("%f", &price[count]) != 1) { + break; } - price[strcspn(price, "\n")] = 0; + + // Clear the newline character left in the input buffer + while (getchar() != '\n'); char normal_dish[MAX_LENGTH]; strcpy(normal_dish, dish_name); - decode(normal_dish); + decode(normal_dish); + if (strstr(normal_dish, slovo) != NULL) { - printf("%s\n%s\n", dish_name, price); + // Print the dish name and formatted price + printf("%s\n%.2f\n", dish_name, price[count]); } count++; } @@ -61,5 +64,3 @@ int main() { printf("Nacitanych %d poloziek.\n", count); return 0; } - -