i've made this in 10 mins, and spent 2 hours trying to figure out why it won't do anything on the terminal and have finally given up and need help. It would be really appreciated if anyone could help. Thanks.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main (int argc, char const *argv[])
{
int waitingRoomCust = 0;
srand(time(NULL));
int barber = fork();
printf("%d\n",barber);
if (barber==0) {
while(1) {
if(waitingRoomCust > 0) {
waitingRoomCust--;
sleep((rand() % 12));
printf("Customer has been given a haircut.");
}
}
}
if(barber!=0) {
while(1) {
if(waitingRoomCust <= 3) {
waitingRoomCust++;
printf("The waiting room has now %i customers.", waitingRoomCust);
}
else {
printf("Waiting room is full, customer has left.");
}
}
}
return 0;
}