Each cake in the counter is a struct Cake: name and price. Write cheapest(cakes, n) to return the name of the cheapest one. There's at least 1; if two cost the same, return the earlier one.
cheapest({{"cheesecake", 28}, {"brownie", 12}, {"tiramisu", 30}}, 3)→'brownie'cheapest({{"donut", 6}}, 1)→'donut'const char *cheapest(struct Cake cakes[], int n)struct Cake {
const char *name;
int price;
};
const char *cheapest(struct Cake cakes[], int n) {
int best = 0;
for (int i = 1; i < n; i++) {
// your code here: if this cake is cheaper than cake best, set best to i
}
return cakes[best].name;
}
Run tries the examples. When they look right, Submit.