Structures within structures for a database

This is a discussion on Structures within structures for a database within the C Programming forums, part of the General Programming Boards category; I'm trying to create a golf handicap management system that takes up to 100 rounds and their statistical info and ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    12

    Structures within structures for a database

    I'm trying to create a golf handicap management system that takes up to 100 rounds and their statistical info and relays it to one structure of a member....which holds their name, handicap, average putts, etc....

    So, the dilemma is, structure for the user, and an array of 100 structures holding round by round information within the user's structure. I'm getting about 100 errors in my compiler and wonder if I'm off on the wrong foot completely.

    Please let me know of any ideas you might have. I want to do this without linked lists if possible, as my instructor would prefer I do it this way for some reason. Here's the code........ (HELP!!)

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<math.h>
    #include<string.h>
    
    FILE *out;
    
    struct golfer1
    {
    	char name[40];
    	double handicap;
    	int totRounds;
    	char homeClub[40];
    	double avgPutts;
    	double avgFwys;
    	double avgGreens;
    	double sandSaves;
    	int sandRounds;
    	struct round[100];
    };
    
    //struct golfer2
    //{
    //	char name[]= 'Dan Thomson';
    //	double handicap = 0;
    //	int totRounds = 0;
    //	char homeClub[]= 'Pitt Meadows GOlf Club';
    //	double avgPutts = 0;
    //	double avgFwys = 0;
    //	double avgGreens = 0;
    //	double sandSaves = 0;
    //	int sandRounds = 0;
    //	struct round[100];
    //};
    //
    //struct golfer3
    //{
    //	char name[]= 'Terry Salchenberger';
    //	double handicap = 0;
    //	int totRounds = 0;
    //	char homeClub[]= 'Pitt Meadows Golf Club';
    //	double avgPutts = 0;
    //	double avgFwys = 0;
    //	double avgGreens = 0;
    //	double sandSaves = 0;
    //	int sandRounds = 0;
    //	struct round[100];
    //};
    //
    //struct golfer4
    //{
    //	char name[]= 'Dustin Vernon';
    //	double handicap = 0;
    //	int totRounds = 0;
    //	char homeClub[] = 'Pitt Meadows Golf Club';
    //	double avgPutts = 0;
    //	double avgFwys = 0;
    //	double avgGreens = 0;
    //	double sandSaves = 0;
    //	int sandRounds = 0;
    //	struct round[100];
    //};
    //
    //struct golfer5
    //{
    //	char name[]= 'Jesse Kurucz';
    //	double handicap = 0;
    //	int totRounds = 0;
    //	char homeClub[]= 'Pitt Meadows Golf Club';
    //	double avgPutts = 0;
    //	double avgFwys = 0;
    //	double avgGreens = 0;
    //	double sandSaves = 0;
    //	int sandRounds = 0;
    //	struct round[100];
    //};
    
    struct round
    {
    	char club[40];
    	double slope;
    	int par;
    	int score;
    	int putts;
    	int fwyHit;
    	int grnHit;
    	int sandSave;
    	int numThrees;
    	int sandAttmpt;
    	double roundHcp;
    };
    
    void main()
    {
    	int choice;
    	int choice1;
    	int choice2;
    	char choice3;
    	char club[40];
    	struct golfer1 golfer1;
    	/*struct golfer2 golfer2;
    	struct golfer3 golfer3;
    	struct golfer4 golfer4;
    	struct golfer5 golfer5;*/
    	struct round round;
    	int i;
    	int a;
    
    	golfer1.name = "Andrew Holtz";
    	golfer1.avgFwys = 0;
    	golfer1.avgGreens = 0;
    	golfer1.avgPutts = 0;
    	golfer1.handicap = 0;
    	golfer1.homeClub = "Pitt Meadows Golf Club";
    	golfer1.sandRounds = 0;
    	golfer1.sandSaves = 0;
    	golfer1.totRounds = 0;
    	
    	
    	printf("\n[1] AndrewH");
    	printf("\n[2] DanT");
    	printf("\n[3] TerryS");
    	printf("\n[4] DustinV");
    	printf("\n[5] JesseK");
    
    	printf("\nPlease choose you name/profile from the list: ");
    	scanf("%d", &choice);
    
    	/*switch(choice)
    	{
    		case 1:
    			a = golfer1;
    			break;
    
    		case 2:
    			a = golfer2;
    			break;
    
    		case 3:
    			a = golfer3;
    			break;
    
    		case 4:
    			a = golfer4;
    			break;
    
    		case 5:
    			a = golfer5;
    			break;
    
    	}*/
    
    	fflush(stdin);
    
    	printf("\n%s", golfer1.name);
    	printf("\nHomeClub: %s", golfer1.homeClub);
    	printf("\nHandicap: %lf", golfer1.handicap);
    	printf("\nRounds Played: %d", golfer1.totRounds);
    	printf("\nAverage Putts: %d", golfer1.avgPutts);
    	printf("\nAverage Fairways: %d", golfer1.avgFwys);
    	printf("\nAverage Greens: %d", golfer1.avgGreens);
    	printf("\nPercentage Sand Saves: %d", golfer1.sandSaves);
    
    	printf("\nTo view a menu press [M], to exit press [E]");
    		scanf("%c", &choice1);
    	fflush(stdin);
    	
    	if(choice1 == 'm' || choice1 == 'M')
    	{
    		printf("\n[1] Enter a score");
    		printf("\n[2] View last 10 rounds");
    		printf("\n[3] Print out the last 10 scores");
    
    		printf("\nPlease make a choice from the list: ");
    		scanf("%d", &choice2);
    		
    		fflush(stdin);
    		
    	if (choice2 == 1 || choice2 == 1)
    	{
    		i = (golfer1.totRounds)-1;
    		
    		printf("Please enter the name of the golf club: ");
    		gets(golfer1.(round[i]).club);
    
    		fflush(stdin);
    		printf("\nPlease enter the slope of the course: ");
    		scanf("%lf", &(golfer1.(round[i]).slope) );
    
    		fflush(stdin);
    		printf("\nPlease enter the par of the course: ");
    		scanf("%d", &(golfer1.(round[i]).par));
    
    		fflush(stdin);
    		printf("\nPlease enter the number of par 3's the course has: ");
    		scanf("%d", &(golfer1.(round[i]).numThrees));
    
    		fflush(stdin);
    		printf("\nPlease enter the number of putts you had: ");
    		scanf("%d", &(golfer1.(round[i]).putts));
    
    		fflush(stdin);
    		printf("\nPlease enter the number of fairways that you hit: ");
    		scanf("%d", &(golfer1.(round[i]).fwyHit));
    
    		fflush(stdin);
    		printf("\nPlease enter the number of greens that you hit: ");
    		scanf("%d", &(golfer1.(round[i]).grnHit));
    
    		fflush(stdin);
    		printf("\nDid you have any sand saves today?(Y/N) ");
    			scanf("%c", &choice3);
    
    		if (choice3 == 'y' || choice3 == 'Y')
    		{
    			fflush(stdin);
    			printf("\nPlease enter the sand saves you had: ");
    			scanf("%d", &(golfer1.(round[i]).sandSave));
    
    			fflush(stdin);
    			printf("\nPlease enter the number of sand traps you were in: ");
    			scanf("%d" , &(golfer1.(round[i]).sandAttmpt));
    
    			golfer1.sandRounds++;
    		}
    
    		golfer1.totRounds++;
    		golfer1.(round[i]).roundHcp = (golfer1.(round[i]).score - golfer1.(round[i]).slope);
    		golfer1.handicap += (golfer1.(round[i]).roundHcp/golfer1.(round[i]).totRounds);
    		golfer1.avgPutts += (golfer1.(round[i]).putts/golfer1.(round[i]).totRounds);
    		golfer1.avgFwys += ((golfer1.(round[i]).fwyHit/(18-golfer1.(round[i]).numThrees))/golfer1.(round[i]).totRounds);
    		golfer1.avgGreens += ((golfer1.(round[i]).grnHit/18)/golfer1.(round[i]).totRounds);
    		golfer1.sandSaves += ((golfer1.(round[i]).sandSave/golfer1.(round[i]).sandAttmpt)/golfer1.(round[i]).sandRounds);
    
    	}
    	else if(choice2 == 2)
    	{
    		i = golfer1.totRounds;
    
    		for(j=0;j<10;j++)
    		{
    			printf("\n %s",golfer1.round[i-9].club);
    			printf("\n %lf",golfer1.round[i-9].slope);
    			printf("\n %d",golfer1.round[i-9].par);
    			printf("\n %d",golfer1.round[i-9].score);
    			printf("\n %d",golfer1.round[i-9].putts);
    			printf("\n %d",golfer1.(round[i-9]).fwyHit);
    			printf("\n %d",golfer1.(round[i-9]).grnHit);
    			printf("\n %d",golfer1.round[i-9].sandSave);
    			printf("\n %d",golfer1.round[i-9].sandAttmpt);
    
    			i++;
    	}
    	i = golfer1.totRounds;
    
    	else if(choice2 == 3)
    	{
    		i = golfer1.totRounds;
    		
    		out = fopen("last10.txt", "w");
    
    		for(j=0;j<10;j++)
    		{
    			fprintf(out, "\n %s",golfer1.round[i-9].club);
    			fprintf(out, "\n %lf",golfer1.round[i-9].slope);
    			fprintf(out, "\n %d",golfer1.round[i-9].par);
    			fprintf(out, "\n %d",golfer1.round[i-9].score);
    			fprintf(out, "\n %d",golfer1.round[i-9].putts);
    			fprintf(out, "\n %d",golfer1.round[i-9].fwyHit);
    			fprintf(out, "\n %d",golfer1.round[i-9].grnHit);
    			fprintf(out, "\n %d",golfer1.round[i-9].sandSave);
    			fprintf(out, "\n %d",golfer1.round[i-9].sandAttmpt);
    			i++;
    		}
    		fclose(out);
    	}
    	}
    
    }
    Thanks in advance everyone

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    #1. You should declare struct round before struct golfer1.

    #2.
    Code:
    struct golfer1
    {
    	char name[40];
    	double handicap;
    	int totRounds;
            char homeClub[40];
    	double avgPutts;
    	double avgFwys;
    	double avgGreens;
    	double sandSaves;
    	int sandRounds;
    	struct round[100];
    };
    You still need a variable name here for your struct round array member. This is a contributor to a large number of your errors.

    #3.
    Code:
    void main()
    The main function returns an int and you'll therefore need an appropriate return at the end of the function.

    #4.
    Code:
     golfer1.name = "Andrew Holtz";
    	golfer1.avgFwys = 0;
    	golfer1.avgGreens = 0;
    	golfer1.avgPutts = 0;
    	golfer1.handicap = 0;
    	golfer1.homeClub = "Pitt Meadoolf Club";
    Such assignments are illegal, you probably want to use the strcpy function instead.

    #5.
    Code:
    fflush(stdin);
    fflush is not for the standard input streams, this is undefined behavior. Check the FAQ.

    #6. Don't use gets. Again, check the FAQ, fgets is a much better replacement.

    #7.
    Code:
    printf("Please enter the name of the golf club: ");
    gets(golfer1.(round[i]).club);
    
    printf("\nPlease enter the slope of the course: ");
    scanf("&#37;lf", &(golfer1.(round[i]).slope) );
    
    printf("\nPlease enter the par of the course: ");
    scanf("%d", &(golfer1.(round[i]).par));
    You've got several places in your code, some noted above, with bad syntax. Get rid of the parenthesis in bold above as an example. Of course, you should have by this point also replaced "round" with whatever variable name you've created to fix #2 above. This issue is also a contributor to a large number of your errors.

    #8.
    Code:
    golfer1.handicap += (golfer1.(round[i]).roundHcp/golfer1.(round[i]).totRounds);
    golfer1.avgPutts += (golfer1.(round[i]).putts/golfer1.(round[i]).totRounds);
    ...
    golfer1.sandSaves += ((golfer1.(round[i]).sandSave/golfer1.(round[i]).sandAttmpt)/golfer1.(round[i]).sandRounds);
    You are accessing the totRounds and sandRounds variables as if they were members of the round struct which it is not.

    #9
    Code:
    for(j=0;j<10;j++)
    {
        printf("\n %s",golfer1.round[i-9].club);
        printf("\n %lf",golfer1.round[i-9].slope);
        printf("\n %d",golfer1.round[i-9].par);
        printf("\n %d",golfer1.round[i-9].score);
        printf("\n %d",golfer1.round[i-9].putts);
        printf("\n %d",golfer1.(round[i-9]).fwyHit);
        printf("\n %d",golfer1.(round[i-9]).grnHit);
        printf("\n %d",golfer1.round[i-9].sandSave);
        printf("\n %d",golfer1.round[i-9].sandAttmpt);
        i++;
    }
    There is no j variable in your code.

    #10
    Code:
    	else if(choice2 == 2)
    	{
    		i = golfer1.totRounds;
    
    		for(j=0;j<10;j++)
    		{
                         ...
    	}
    	i = golfer1.totRounds;
    
    	else if(choice2 == 3)
    	{
    This is an illegal "else if". A contributor to this error is the poor indentation here.

    There may be more problems, those are the ones I see. Any compiler would have given you plenty of error/warning messages explaining most of these things.
    Last edited by hk_mp5kpdw; 04-30-2008 at 06:10 AM.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,420
    Is this someone else's code or just code you copied from somewhere?
    Surely you should be able to correct the errors if you made the code yourself?
    There are some very easy errors here that anyone should be able to correct.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  2. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM
  3. database application help.
    By Billy Baroo in forum Linux Programming
    Replies: 1
    Last Post: 09-02-2002, 06:23 PM
  4. File Database & Data Structure :: C++
    By kuphryn in forum C++ Programming
    Replies: 0
    Last Post: 02-24-2002, 10:47 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21