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