This commit is contained in:
Deinerovych 2024-09-26 23:27:49 +02:00
parent 955d347cc6
commit 20bb9845a0

View File

@ -36,10 +36,17 @@ int contains_substring(char *food_name, char *ingredient) {
return 0; return 0;
} }
void format_price(char *formatted_price, const char *price) {
double value;
sscanf(price, "%lf", &value);
sprintf(formatted_price, "%.2f", value);
}
int main() { int main() {
char ingredient[100]; char ingredient[100];
char food_name[200]; char food_name[200];
char price[20]; char price[20];
char formatted_price[20];
int count = 0; int count = 0;
printf("Zadaj hladanu surovinu:\n"); printf("Zadaj hladanu surovinu:\n");
@ -56,8 +63,10 @@ int main() {
} }
price[strcspn(price, "\n")] = '\0'; price[strcspn(price, "\n")] = '\0';
format_price(formatted_price, price);
if (contains_substring(food_name, ingredient)) { if (contains_substring(food_name, ingredient)) {
printf("%s\n%s\n", food_name, price); printf("%s\n%s\n", food_name, formatted_price);
} }
count++; count++;