Kodewick
Start learning →
Mini challenge←→0 / 70

Bakery receipt

#009Mini challengeOutputArrays6 min

The bakery receipt: one line per item, the name with %-10s (10 places, on the left) and the price with %6.2f (6 places, two decimals), while adding the price to total. The Total line is already written: copy its format.

Should show
Bread       3.50
Croissant   2.25
Muffin      2.75
Total       8.50
main.c
#include <stdio.h>

int main(void) {
    const char *items[3] = {"Bread", "Croissant", "Muffin"};
    double prices[3] = {3.5, 2.25, 2.75};
    double total = 0;
    for (int i = 0; i < 3; i++) {
        // your code here: printf this item's name and price
        // your code here: add this price to total
    }
    printf("%-10s%6.2f\n", "Total", total);
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.