The code is:
Code:
#include <stdio.h>
void connect();
void disconnect();
void print();
void query();
int countries[100][100];
int main ()
{
char choice;
printf("***MAIN MENU***\n");
printf("(C) Connect two countries\n");
printf("(D) Disconnect two countries\n");
printf("(P) Print all connections between countries\n");
printf("(Q) Query all connecting countries\n");
printf("(X) Exit the program\n");
printf("---\n");
printf("Please enter the first letter of your choice, then hit Return\n");
scanf("%c", &choice);
switch (choice){
case 'C':
connect();;
break;
case 'D':
disconnect();
break;
case 'P':
print();
break;
case 'Q':
query();
break;
case 'X':
return 0;
default:
fprintf(stderr, "%c is an invalid choice\n", choice);
return 1;
}
return 0;
}
void connect(){
int c1, c2;
printf("Please enter the two numbers of the countries you wish to connect.\n");
scanf("%d %d", &c1, &c2);
countries[c1-1][c2-1] = 1;
countries[c2-1][c1-1] = 1;
main();
}
The problem is that after I enter C and go to the connect procedure. After the connect procedure finishes I want to go back to main again. The first time the program runs it allows me to enter a choice, but however after I enter the choice C and go to the connect procedure and want to return back to main it won't allow me to enter a choice!
It just goes through as I didn't enter a choice. How can I fix this?