1: You can't nest functions.
2: You can't use variables unless you've declared them first.
This works for me, but I had to remove the calls to nonstandard conio functions:
Code:
#include <conio.h>
#include <stdio.h>
#include <string.h>
char stop_name[BUFSIZ] = {0};
void bus_stop_name ( int number );
int main ( void )
{
int boarding, destination, adults, children, oaps;
printf("*******************\n");
printf("Welcome to BromBus\n");
printf("*******************\n");
printf("\nWhat is your boarding stop number: ");
scanf("%d", &boarding);
bus_stop_name(boarding);
printf("Boarding at %s", stop_name);
printf("\nWhat is your destination stop number: ");
scanf("%d",&destination);
bus_stop_name(destination);
printf("Travelling to %s", stop_name);
printf("\nHow many adults are travelling: ");
scanf("%d", &adults);
printf("\nHow many children are travelling: ");
scanf("%d", &children);
printf("\nHow many oaps are travelling: ");
scanf("%d", &oaps);
return 0;
}
void bus_stop_name ( int number )
{
switch(number)
{
case 1: strcpy(stop_name,"Tescos"); break;
case 2: strcpy(stop_name,"The Glades"); break;
case 3: strcpy(stop_name, "East Street"); break;
case 4: strcpy(stop_name, "Downham"); break;
case 5: strcpy(stop_name, "Catford"); break;
case 6: strcpy(stop_name, "Catford High Street"); break;
case 7: strcpy(stop_name, "Catford Dogs"); break;
case 8: strcpy(stop_name, "Ladywell"); break;
case 9: strcpy(stop_name, "Ladywell Arena"); break;
case 10: strcpy(stop_name, "Lewisham"); break;
case 11: strcpy(stop_name, "The Riverdale"); break;
case 12: strcpy(stop_name, "New Cross Road"); break;
case 13: strcpy(stop_name, "New Cross Gate"); break;
case 14: strcpy(stop_name, "Peckham High Street"); break;
case 15: strcpy(stop_name, "Peckham Rye"); break;
case 16: strcpy(stop_name, "Camberwell Green"); break;
case 17: strcpy(stop_name, "Elephant & Castle"); break;
case 18: strcpy(stop_name, "London Bridge"); break;
case 19: strcpy(stop_name, "Charing Cross"); break;
case 20: strcpy(stop_name,"Oxford Street"); break;
}
}
However, to save yourself a lot of trouble with that switch statement, you could simply declare an array of strings with each street name and then use number as the index:
Code:
void bus_stop_name ( int number )
{
static const char *stops[NUMSTOPS] =
{
{"Tescos" },{"The Glades" },{"East Street" },
{"Downham" },{"Catford" },{"Catford High Street"},
{"Catford Dogs" },{"Ladywell" },{"Ladywell Arena" },
{"Lewisham" },{"The Riverdale" },{"New Cross Road" },
{"New Cross Gate" },{"Peckham High Street"},{"Peckham Rye" },
{"Camberwell Green"},{"Elephant & Castle" },{"London Bridge" },
{"Charing Cross" },{"Oxford Street" },
};
if ( number > 0 && number < NUMSTOPS )
strcpy ( stop_name, stops[number - 1] );
}
-Prelude