Kodewick
Start learning →
Mini challenge←→0 / 60

Bakery orders

#057Mini challengeOutputvector6 min

The bakery is printing today's order slip. breads and counts go together: bread i has counts[i] ordered. In the loop, skip any with 0; for the others show one line such as croissant x3 and add the count to total. The last line is already written.

Should show
croissant x3
baguette x2
muffin x5
total: 10
main.cpp
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    vector<string> breads = {"croissant", "bagel", "baguette", "muffin"};
    vector<int> counts = {3, 0, 2, 5};
    int total = 0;
    for (int i = 0; i < (int)breads.size(); i++) {
        // your code here: skip a 0; otherwise show a line and add to total
    }
    cout << "total: " << total << endl;
    return 0;
}
Ctrl + Enter runs too
Result

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