A line on the bakery order is a struct Item: name, price and how many. Finish item_total(item) to work out what that line costs: buying 3 or more makes each one 1 cheaper. main tries two lines: 2 bagels and 3 muffins.
bagel: 8 muffin: 12
#include <stdio.h>
struct Item {
const char *name;
int price;
int qty;
};
int item_total(struct Item item) {
int price = item.price;
// your code here: if qty is 3 or more, take 1 off price
return price * item.qty;
}
int main(void) {
struct Item bagels = {"bagel", 4, 2};
struct Item muffins = {"muffin", 5, 3};
printf("%s: %d\n", bagels.name, item_total(bagels));
printf("%s: %d\n", muffins.name, item_total(muffins));
return 0;
}
Run tries the examples. When they look right, Submit.