Last active
December 12, 2020 23:08
-
-
Save Tombo1001/5025797 to your computer and use it in GitHub Desktop.
Taxi Rank Code #stage1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MAX_SIZE 100 | |
void push ( int a[ ], int *top , int x); | |
int pop ( int a[ ], int *top); | |
void print ( int a[ ], int top ); | |
int exit( ); | |
int initialise( ); | |
///////////////////////////////////////// | |
int main( ) | |
{ | |
int option; | |
printf("Welcome to the Taxi Rank Tracker!\n"); | |
printf("1 - Initialise\n"); | |
printf("2 - Taxi Leaving\n"); | |
printf("3 - Taxi Arriving\n"); | |
printf("4 - Show Current Rank\n"); | |
printf("\n99 - Exit\n"); | |
printf("\nSelect an option to continue: "); | |
scanf("%d", &option); | |
if(option == 1 || option == 2 || option == 3 || option == 4 || option == 99) | |
{ | |
if(option == 99) | |
{ | |
exit(); | |
option = 0; | |
} | |
if(option == 1) | |
{ | |
initialise(); | |
option = 0; | |
} | |
if(option == 2) | |
{ | |
//something | |
option = 0; | |
} | |
if(option == 3) | |
{ | |
//something | |
option = 0; | |
} | |
if(option == 4) | |
{ | |
//print(); | |
option = 0; | |
main(); | |
} | |
} | |
else | |
{ | |
printf("Please enter a valid option"); | |
main(); | |
} | |
} | |
///////////////////////////////////// | |
///////////////////////////////////// | |
int initialise() | |
{ | |
int s[MAX_SIZE] ; | |
int top = 0 , temp; | |
int total_taxis, i; | |
printf("Enter Number of Taxis (1 - 6): "); | |
scanf("%d", &total_taxis); | |
if (total_taxis<7 && total_taxis>0) | |
{ | |
for(i=1; i<total_taxis+1; i++) | |
{ | |
push( s , &top, i); | |
} | |
} | |
else | |
{ | |
if(total_taxis<1) | |
{ | |
printf("Error - more than 1 taxi must be entered\n"); | |
} | |
if(total_taxis>6) | |
{ | |
printf("Error - maximum number of taxis is 6\n"); | |
} | |
main(); | |
} | |
print(s, top); | |
temp = pop(s, &top); | |
print(s, top); | |
main(); | |
} | |
///////////////////////////////////// | |
///////////////////////////////////// | |
void push( int a[ ], int *top , int x) | |
{ // do nothing if stack full. | |
if ( *top < MAX_SIZE ) | |
{ | |
a[*top] = x; | |
(*top)++; | |
} | |
} | |
///////////////////////////////////// | |
///////////////////////////////////// | |
int pop( int a[ ], int *top) | |
{ // -1 returned if stack empty. | |
if ( *top > 0 ) | |
{ | |
(*top)--; | |
return(a[*top]); | |
} | |
else return -1; | |
} | |
//////////////////////////////////// | |
//////////////////////////////////// | |
void arrive() | |
{ | |
//taxi arrives | |
} | |
/////////////////////////////////// | |
/////////////////////////////////// | |
void depart() | |
{ | |
//taxi leaves | |
} | |
/////////////////////////////////// | |
/////////////////////////////////// | |
void print ( int a[ ], int top ) | |
{ | |
int i ; | |
if ( top > 0 ) | |
{ | |
printf("\n--------------\n"); | |
printf(" Number of Taxis in rank: %d\n", top); | |
for (i = 0; i < top ; i++) | |
printf("%6d\n", a[i] ); | |
} | |
else printf(" Number of Taxis in rank: %d\n", top); | |
printf("--------------\n\n"); | |
} | |
///////////////////////////////// | |
///////////////////////////////// | |
void find() | |
{ | |
} | |
///////////////////////////////// | |
///////////////////////////////// | |
int exit() | |
{ | |
int answer; | |
printf("\nAre you sure you want to exit? [0 = yes / 1 = no]: "); | |
scanf("%d", &answer); | |
printf(answer); | |
if(answer == 0 || answer == 1) | |
{ | |
if(answer == 0) | |
{ | |
printf("\nExiting ...\n"); | |
return 0; | |
} | |
if(answer == 1) | |
{ | |
main(); | |
} | |
} | |
else | |
{ | |
printf("\nError - you must enter 0 or 1\n"); | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment