icp/oer/courses/c-newcomers/sections/04-supermarket/04-customer/program.c

58 lines
1.3 KiB
C

#include <stdio.h>
#include <stdbool.h>
#include "supermarket.h"
#define CUSTOMER_ITEM_COUNT 5
// TODO: Implement the struct here with an array of 5 items and a packing speed
int main()
{
bool CustomerHasItems = true;
int TimePassed = 0;
// TODO: replace this with a your struct and add a packing speed of 2
item CustomerItems[CUSTOMER_ITEM_COUNT] = {tissues, pasta, tomato_sauce, bread, butter};
// NOTE: To access a member of your customer struct you have to use the .-operator
// e.g Customer.PackingSpeed = 23;
// NOTE: the Time-array is now a global Variable
initTimeTable();
int ItemsLeft = CUSTOMER_ITEM_COUNT;
state CurrentState = STATE_ready_for_item;
int TimeToScan = 0;
while(CustomerHasItems)
{
if(CurrentState == STATE_ready_for_item)
{
int CurrentItemIndex = CUSTOMER_ITEM_COUNT - ItemsLeft;
// TODO: Change this to use the customer struct
item CurrentItem = CustomerItems[CurrentItemIndex];
// TODO: add the packing speed on top of the scanning time
TimeToScan = Time[CurrentItem];
CurrentState = STATE_scanning;
}
else
{
TimePassed ++;
TimeToScan --;
if (TimeToScan == 0)
{
ItemsLeft--;
CurrentState = STATE_ready_for_item;
}
printf("Time since start: %d. Scanning a product. %d to go.\n", TimePassed, ItemsLeft);
}
if(!ItemsLeft)
CustomerHasItems = false;
}
}