hi any chance anyone can help me with C programming, im very rubbish at codes
i am required to code up in C, a program to simulate a taxi rank that is implemented as a queue via an array that can hold up to a maximum of six taxis.
When a taxi arrives, it joins the rear of the queue. When a taxi departs, the first taxi in the rank is used and its departure is logged.
A "rolling menu" comprising integer codes as specified below is used until 0 is entered to exit the simulation.
Code Function Detailed Operation(s)
1 arrive: read taxi number (an integer) and
add specified taxi number to rear of rank.
2 depart: remove first taxi from front of rank
report taxi departure.
3 print: print contents (including empty) of the rank.
4 find: read a taxi number. If it is in the rank report
its position, otherwise report its absence.
0 exit: cleanly exit the program
ive done this code but i need help editing it, for the above answers
Code:
#include <stdio.h>
#include <Stdafx.h>
#define MAX 100
void print_menu(int n);
void main()
{
int c;
int a[MAX];
int top = 0;
int reg;
int temp[MAX];
print_menu(1);
scanf_s("%d", &c);
while (c != 8)
{
if (c == 1)
{
// Scan in registration
printf("Please enter Taxi Registration Number\n");
scanf("%d", ®);
a[top] = reg;
top++;
// Call print_menu
print_menu(1);
scanf("%d", &c);
}
else if (c == 2)
{
//remove from front
int b;
for(b = 0; b <= top; b++)
{
temp[b] = a[b+1];
}
for (b = 0; b <= top; b++)
{
a[b] = temp[b];
}
top--;
printf("Taxi has left\n");
//print menu
print_menu(1);
scanf("%d", &c);
}
else if (c == 3)
{
//search taxi
int k;
int notfound = -1;
printf("Please enter taxi registration number\n");
scanf("%d", ®);
for (k = 0; k <= top; k++)
{
if(a[k] == reg)
{
printf("Taxi %d found in position %d\n", reg, k+1);
}
else
{
notfound++;
}
if (notfound == top)
{
printf("Taxi not found\n");
}
}
//print taxi menu
print_menu(1);
scanf("%d", &c);
}
else if (c == 4)
{
// print taxi's
int i, taxnum;
taxnum = 1;
if (top == 0)
{
printf("No Taxi's in queue\n");
}
else
{
for(i = 0; i < top; i++)
{
printf("Taxi number %d: ", taxnum++);
printf("%d\n", a[i]);
}
}
// call print_menu
print_menu(1);
scanf("%d", &c);
}
else if (c == 5)
{
//print taxi in the front of queue
if (a[0] < 0)
{
printf("There are no taxi's in the queue\n");
}
else
{
printf("First taxi in the queue is: %d\n", a[0]);
}
//print taxi menu
print_menu(1);
scanf("%d", &c);
}
else if (c == 6)
{
//print taxi last in queue
if (top -1 < 0)
{
printf("There are no taxi's in the queue\n");
}
else
{
printf("Last taxi in the queue is: %d\n",a[top - 1]);
}
// print menu
print_menu(1);
scanf("%d", &c);
}
else if (c == 7)
{
//length of queue
if (top ==1)
{
printf("There is %d Taxi in the queue\n", top);
}
else
{
printf("There are %d Taxi's in the queue\n", top);
}
//print menu
print_menu(1);
scanf("%d", &c);
}
else
{
printf("**Invalid menu option**\n");
print_menu(1);
scanf("%d", &c);
}
}
}
// Print menu
void print_menu(int n)
{
printf("*************\n");
printf("* Taxi Menu *\n");
printf("*************\n");
printf("* 1. Arrive *\n");
printf("* 2. Leave *\n");
printf("* 3. Search *\n");
printf("* 4. Print *\n");
printf("* 5. Front *\n");
printf("* 6. Back *\n");
printf("* 7. Length *\n");
printf("* 8. Exit *\n");
printf("*************\n");
}