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