Обновить cv1/program.c
This commit is contained in:
		
							parent
							
								
									d730335393
								
							
						
					
					
						commit
						6170be7394
					
				| @ -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; | ||||
| @ -28,10 +27,9 @@ void decode(char *text) { | ||||
| int main() { | ||||
|     char slovo[MAX_LENGTH]; | ||||
|     char dish_name[MAX_LENGTH]; | ||||
|     char price[MAX_LENGTH]; | ||||
|     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; | ||||
| @ -43,17 +41,22 @@ int main() { | ||||
|             break; | ||||
|         } | ||||
|         dish_name[strcspn(dish_name, "\n")] = 0; | ||||
|         // Načítanie ceny jedla
 | ||||
|         if (fgets(price, MAX_LENGTH, stdin) == NULL || strcmp(price, "\n") == 0) { | ||||
| 
 | ||||
|         // 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); | ||||
| 
 | ||||
|         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; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user