Обновить cv1/program.c
This commit is contained in:
parent
6170be7394
commit
432668568e
@ -5,7 +5,6 @@
|
|||||||
#define MAX_DISHES 100
|
#define MAX_DISHES 100
|
||||||
#define MAX_LENGTH 100
|
#define MAX_LENGTH 100
|
||||||
|
|
||||||
|
|
||||||
void decode(char *text) {
|
void decode(char *text) {
|
||||||
for (int i = 0; text[i] != '\0'; i++) {
|
for (int i = 0; text[i] != '\0'; i++) {
|
||||||
switch (text[i]) {
|
switch (text[i]) {
|
||||||
@ -23,44 +22,36 @@ void decode(char *text) {
|
|||||||
text[i] = tolower(text[i]);
|
text[i] = tolower(text[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
char slovo[MAX_LENGTH];
|
char slovo[MAX_LENGTH];
|
||||||
char dish_name[MAX_LENGTH];
|
char dish_name[MAX_LENGTH];
|
||||||
float price[MAX_DISHES]; // Use float array for prices
|
float price[MAX_DISHES];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
printf("Zadaj hladanu surovinu:\n");
|
printf("Zadaj hladanu surovinu:\n");
|
||||||
fgets(slovo, MAX_LENGTH, stdin);
|
fgets(slovo, MAX_LENGTH, stdin);
|
||||||
slovo[strcspn(slovo, "\n")] = 0;
|
slovo[strcspn(slovo, "\n")] = 0;
|
||||||
decode(slovo);
|
decode(slovo);
|
||||||
|
|
||||||
printf("Zadaj jedalny listok:\n");
|
printf("Zadaj jedalny listok:\n");
|
||||||
while (1) {
|
while (1) {
|
||||||
if (fgets(dish_name, MAX_LENGTH, stdin) == NULL || strcmp(dish_name, "\n") == 0) {
|
if (fgets(dish_name, MAX_LENGTH, stdin) == NULL || strcmp(dish_name, "\n") == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dish_name[strcspn(dish_name, "\n")] = 0;
|
dish_name[strcspn(dish_name, "\n")] = 0;
|
||||||
|
|
||||||
// Read the price as a float
|
// Read the price as a float
|
||||||
if (scanf("%f", &price[count]) != 1) {
|
if (scanf("%f", &price[count]) != 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear the newline character left in the input buffer
|
// Clear the newline character left in the input buffer
|
||||||
while (getchar() != '\n');
|
while (getchar() != '\n');
|
||||||
|
|
||||||
char normal_dish[MAX_LENGTH];
|
char normal_dish[MAX_LENGTH];
|
||||||
strcpy(normal_dish, dish_name);
|
strcpy(normal_dish, dish_name);
|
||||||
decode(normal_dish);
|
decode(normal_dish);
|
||||||
|
|
||||||
if (strstr(normal_dish, slovo) != NULL) {
|
if (strstr(normal_dish, slovo) != NULL) {
|
||||||
// Print the dish name and formatted price
|
// Print the dish name and formatted price
|
||||||
printf("%s\n%.2f\n", dish_name, price[count]);
|
printf("%s\n%.2f\n", dish_name, price[count]);
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Nacitanych %d poloziek.\n", count);
|
printf("Nacitanych %d poloziek.\n", count);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user