I apologize for the long code, but this is part of a big project for school and I tried to consolidate as much as I could while still being able to compile it. My issue is that when I access the getFisherman()
function and select register a fisher man from the menu. The first thing that it's supposed to ask for is the user's SSN number then store the user input in an array. However, when you select the register a fisherman option, it skips over the SSN user input and goes right to the first name option instead. I can't figure out why. Any help would be appreciated. I'm also new to this so any other advice would be appreciated. Thank you very much!
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <mem.h>
struct Fisherman
{
//declare all attributes: ssn, first, last, phone, email
//optional attributes: disqualified of type boolean
int ssn[10];
char fName[100];
char lName[100];
int phoneNo[10];
char email[100];
}typedef Fisherman;
Fisherman F1;
int mainMenu();
int FishermanMenu();
void getFisherman();
int main()
{
//declare all working variables: mOption, FManOption, COption...etc...
int MOption = 0;
int FManOption = 0;
int FOption = 0;
int COption = 0;
int userChoice = 0;
//declarations for all arrays of struct
Fisherman F1[100];
//declare a pointer to an array of struct using malloc() for fisherman, fish, catch
Fisherman* pFisherman = (Fisherman*)malloc(100 * sizeof(Fisherman));
//process:
printf("Please select 1 to start the program or 0 to quit: ");
scanf("%d", &userChoice);
while(userChoice != 1 && userChoice != 0)
{
printf("Invalid selection! Please type a 1 or a 0: ");
scanf("%d", &userChoice);
}//end (userChoice != 1 && userChoice != 0)
if(userChoice != 1)
{
printf("Thank you for wasting my time! Have a great day!\n");
return 0;
}
while(MOption != 5)
{
MOption = mainMenu();
switch(MOption)
{
case 1: FManOption = FishermanMenu();
if(FManOption != 3)
{
switch(FManOption)
{
case 1: getFisherman();//get a fisherman
//count fisherman
break;
case 2:
//prompt for a ssn, validate, search
//if found display everything about this fisherman
break;
case 3: getch();
//reset FManOption
break;
default: printf("\nInvalid selection! Please select from one of the menu options\n");
}//end switch(FManOption)
}//end while(FManOption != 3)
break;
}
}
}
int mainMenu(MOption)
{
printf("\n-------Welcome to the Fishing Tournament Main Menu!-------\n");
printf("1 - Fisherman menu\n");
printf("2 - Fish menu\n");
printf("3 - Tournament(Catch) menu\n");
printf("4 - Close Tournament (determine winner)\n");
printf("5 - Quit Program\n\n");
printf("Please select a menu option: ");
scanf("%d", &MOption);
if(MOption > 5 || MOption < 1)
do /* check scanf() return value for input errors */
{
printf("\nInvalid selection! Please select from one of the menu options\n");
printf("1 - Fisherman menu\n");
printf("2 - Fish menu\n");
printf("3 - Tournament(Catch) menu\n");
printf("4 - Close Tournament (determine winner)\n");
printf("5 - Quit Program\n\n");
printf("Please select a menu option: ");
scanf("%d", &MOption);
}
while(MOption > 5 || MOption < 1);
return MOption; /* finally return the final correct option */
}//end main menu
//-----------------------------------------------------------
int FishermanMenu(FManOption)
{
printf("\n-------Fisherman Menu-------\n");
printf("1 - Register fisherman\n");
printf("2 - Search fisherman\n");
printf("3 - Go back to main menu\n");
printf("Please select a menu option: ");
scanf("%d", &FManOption);
if(FManOption > 3 || FManOption < 1)
do /* check scanf() return value for input errors */
{
printf("\nInvalid selection! Please select from one of the menu options\n");/* handle input error */
printf("1 - Register fisherman\n");
printf("2 - Search fisherman\n");
printf("3 - Go back to main menu\n");
printf("Please select a menu option: ");
scanf("%d", &FManOption);
}
while(FManOption > 3 || FManOption < 1);
return FManOption; /* finally return the final correct option */
}//end Fisherman Menu
void getFisherman()
{
int userSelection = 0;
int ssn[100];
char fName[100];
char lName[100];
int phoneNo[100];
char email[100];
printf("Please enter the fisherman's SSN:\n");
fgets(ssn, 40, stdin);
printf("Please enter the fisherman's first name: ");
fgets(fName, 40, stdin);
printf("Please enter the fisherman's last name: ");
fgets(lName, 40, stdin);
printf("Please enter the fisherman's phone number: ");
fgets(phoneNo, 40, stdin);
printf("Please enter the fisherman's email address: ");
fgets(email, 40, stdin);
printf("Fisherman has been registered!\n");
printf("Press 1 to register another fisherman or 0 to return back to main menu: ");
scanf("%d", &userSelection);
if(userSelection == 1)
getFisherman();
while(userSelection > 1 || userSelection < 0)
{
printf("Invalid selection! Please select 1 or 0: ");
scanf("%d", &userSelection);
break;
}
//use fgets and all associated functions and pointer to get data about a
//fisherman
}//end getFisherman