45 lines
1.9 KiB
Markdown
45 lines
1.9 KiB
Markdown
|
Now that the cashier can scan items, the next step will be to have different items which take different amount of time.
|
||
|
|
||
|
## Model
|
||
|
|
||
|
In our model we now not only have to track the amount of items, but also the type. The items of the customer are stored in the ``CustomerItems`` array.
|
||
|
You could have stored each item type as a different number, but this gets confusing and hard to maintain. Thats why we used an enum. We talk about how enums work later.
|
||
|
|
||
|
To model the time each of these item needs, we have an array ``Time``, which associates with each item type a unique time.
|
||
|
|
||
|
Now that items take different amounts of time, it gets interessting how long the whole scanning process took. For that we update the time in the variable ``TimePassed``.
|
||
|
The time is counted in secconds.
|
||
|
|
||
|
## Knowledge
|
||
|
|
||
|
Know back to how enums work. An enum is a way to declare new types. In the background it only binds a number to a name. This makes your code more readable and easier to change,
|
||
|
because the numbers are automatically generated. It doesn't matter if you add one member or delete one or change the order.
|
||
|
|
||
|
Here is an example of an enum for food types.
|
||
|
|
||
|
typedef enum
|
||
|
{
|
||
|
Burger,
|
||
|
Pizza,
|
||
|
Steak,
|
||
|
Salad,
|
||
|
Porkchop,
|
||
|
|
||
|
Food_type_count,
|
||
|
}food;
|
||
|
|
||
|
The last line ``Food_type_count`` is a nice trick to get the amount of members of an enum. This only works because the compiler, the program which translates your code into machine readable code,
|
||
|
just counts up the numbers. In this case Burger is 0 and Pizza is 1 ... and Food_type_count is 5;
|
||
|
You could then use this for example to associate a kcal-value to them with an array.
|
||
|
|
||
|
food kcal[Food_type_count];
|
||
|
kcal[Burger] = 600;
|
||
|
kcal[Salad] = 150;
|
||
|
|
||
|
etc.
|
||
|
|
||
|
This may not be the most elegant solution, but it is a pretty simple one.
|
||
|
|
||
|
## Task
|
||
|
|
||
|
Your task is to implement the items enum and update the amount of time depending on the scanned item.
|