usaa24/cv1/program.c

78 lines
1.4 KiB
C
Raw Normal View History

2024-09-30 11:43:46 +00:00
#include <string.h>
#include <stdio.h>
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
void replace(char* DishName);
struct MenuItem {
char category[50];
char dish[50];
float price;
};
char answer1[100];
int main(void) {
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
struct MenuItem menu[] = {
{"Pizza", "Margarita", 4.4},
{"Pizza", "Cucumber", 4.4},
{"Pizza", "Ajika", 4.4},
{"Pizza", "Paperoni", 4.4}
};
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
printf("Zadaj hladanu surovinu: ");
fgets(answer1, 100, stdin);
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
if (answer1[strlen(answer1) - 1] == '\n') {
answer1[strlen(answer1) - 1] = '\0';
}
int MenuSize = sizeof(menu) / sizeof(menu[0]);
int found = 0;
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
for (size_t i = 0; i < MenuSize; i++) {
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
if (strstr(menu[i].dish, answer1) != NULL) {
found = 1;
2024-09-30 16:41:25 +00:00
replace(menu[i].dish);
printf("Chcete to to: %s, Cena: %.2f\n", menu[i].dish, menu[i].price);
2024-09-30 11:43:46 +00:00
}
}
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
if (!found) {
printf("Zadana surovina nebola najdena.\n");
}
return 0;
}
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
void replace(char* DishName) {
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
char original[] = "aAeEiIoOsSzZ";
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
char replacement[] = "443311005522";
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
int l = strlen(DishName);
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
for (int i = 0; i < l; i++) {
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
for (int j = 0; j < strlen(original); j++) {
if (DishName[i] == original[j]) {
2024-09-30 16:41:25 +00:00
2024-09-30 11:43:46 +00:00
DishName[i] = replacement[j];
break;
}
}
}
2024-09-30 12:35:14 +00:00
}
2024-09-30 16:41:25 +00:00