ok need a bit of help.
got a program to set up football league table and input all the scores etc etc
just tryin to figure a way to add scores and that from there, also the display code seems a bit messy anyway i can put it into a incremental loop?
well the code is....
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 8
#define TRUE 1
#define FALSE 0
void prior_insertion(void);
void draw_table (void);
void insertion_sort (void);
void draw_sorted (void);
void gfor_against (void);
void sort_alpha (void);
struct
{
char team[20];
int played;
int points;
int goalsf;
int goalsa;
int goalsd;
}arrdetails[8];
main()
{
prior_insertion();
draw_table();
insertion_sort();
gfor_against();
sort_alpha();
draw_sorted ();
}
void prior_insertion(void)
{
/*teams*/
strcpy(arrdetails[0].team,"Stoke City");
strcpy(arrdetails[1].team,"Manchester City");
strcpy(arrdetails[2].team,"Port Vale");
strcpy(arrdetails[3].team,"Derby County");
strcpy(arrdetails[4].team,"Birmingham Town");
strcpy(arrdetails[5].team,"Crystal Palace");
strcpy(arrdetails[6].team,"Luton");
strcpy(arrdetails[7].team,"Hull City");
/*played*/
arrdetails[0].played=3;
arrdetails[1].played=3;
arrdetails[2].played=3;
arrdetails[3].played=3;
arrdetails[4].played=3;
arrdetails[5].played=3;
arrdetails[6].played=3;
arrdetails[7].played=3;
/*points*/
arrdetails[0].points=5;
arrdetails[1].points=3;
arrdetails[2].points=1;
arrdetails[3].points=9;
arrdetails[4].points=7;
arrdetails[5].points=5;
arrdetails[6].points=1;
arrdetails[7].points=1;
/*goalsfor*/
arrdetails[0].goalsf=4;
arrdetails[1].goalsf=5;
arrdetails[2].goalsf=2;
arrdetails[3].goalsf=7;
arrdetails[4].goalsf=4;
arrdetails[5].goalsf=4;
arrdetails[6].goalsf=0;
arrdetails[7].goalsf=0;
/*goalsagainst*/
arrdetails[0].goalsa=3;
arrdetails[1].goalsa=6;
arrdetails[2].goalsa=6;
arrdetails[3].goalsa=2;
arrdetails[4].goalsa=2;
arrdetails[5].goalsa=3;
arrdetails[6].goalsa=2;
arrdetails[7].goalsa=2;
}
void draw_table (void)
{
printf("BELOW IS BEFORE AN INSERTION SORT\n");
printf("\t\t\tPlayed\tPoints\tGoals for\tGoals against\n");
printf("\n");
printf("%s \t\t %d \t %d \t %d \t \t %d\n",arrdetails[0].team,arrdetails[0].played,arrdetails[0].points,arrdetails[0].goalsf,arrdetails[0].goalsa);
printf("%s \t %d \t %d \t %d \t \t %d\n",arrdetails[1].team,arrdetails[1].played,arrdetails[1].points,arrdetails[1].goalsf,arrdetails[1].goalsa);
printf("%s \t\t %d \t %d \t %d \t \t %d\n",arrdetails[2].team,arrdetails[2].played,arrdetails[2].points,arrdetails[2].goalsf,arrdetails[2].goalsa);
printf("%s \t\t %d \t %d \t %d \t \t %d\n",arrdetails[3].team,arrdetails[3].played,arrdetails[3].points,arrdetails[3].goalsf,arrdetails[3].goalsa);
printf("%s \t %d \t %d \t %d \t \t %d\n",arrdetails[4].team,arrdetails[4].played,arrdetails[4].points,arrdetails[4].goalsf,arrdetails[4].goalsa);
printf("%s \t\t %d \t %d \t %d \t \t %d\n",arrdetails[5].team,arrdetails[5].played,arrdetails[5].points,arrdetails[5].goalsf,arrdetails[5].goalsa);
printf("%s \t\t\t %d \t %d \t %d \t \t %d\n",arrdetails[6].team,arrdetails[6].played,arrdetails[6].points,arrdetails[6].goalsf,arrdetails[6].goalsa);
printf("%s \t\t %d \t %d \t %d \t \t %d\n",arrdetails[7].team,arrdetails[7].played,arrdetails[7].points,arrdetails[7].goalsf,arrdetails[7].goalsa);
}
void insertion_sort (void)
{
int pinsert;
int temp;
int z,i,in,gap;
int value;
char tmpteam[20];
int tmpplayed;
int tmppoints;
int tmpgoalsf;
int tmpgoalsa;
z = 0;
value=0;
for (z = 0; z < MAX; z++)
{
while (arrdetails[z].points > arrdetails[z + 1].points)
{
strcpy(tmpteam,arrdetails[z+1].team);
tmpplayed=arrdetails[z+1].played;
tmppoints=arrdetails[z+1].points;
tmpgoalsf=arrdetails[z+1].goalsf;
tmpgoalsa=arrdetails[z+1].goalsa;
strcpy(arrdetails[z+1].team,arrdetails[z].team);
arrdetails[z+1].played=arrdetails[z].played;
arrdetails[z+1].points=arrdetails[z].points;
arrdetails[z+1].goalsf=arrdetails[z].goalsf;
arrdetails[z+1].goalsa=arrdetails[z].goalsa;
strcpy(arrdetails[z].team,tmpteam);
arrdetails[z].played=tmpplayed;
arrdetails[z].points=tmppoints;
arrdetails[z].goalsf=tmpgoalsf;
arrdetails[z].goalsa=tmpgoalsa;
z--;
}
}
}
void gfor_against (void)
{
int value,z,i,gap,in,x;
char tmpteam[20];
int tmpplayed;
int tmppoints;
int tmpgoalsf;
int tmpgoalsa;
int alpha;
x = 0;
for (z = 0; z < MAX; z++)/*work out the goals difference*/
{
arrdetails[z].goalsd=arrdetails[z].goalsf-arrdetails[z].goalsa;
}
for (z = 0; z < MAX; z++)
{
if(arrdetails[z].points == arrdetails[z+1].points)
{
while (arrdetails[z].goalsd > arrdetails[z + 1].goalsd)
{
strcpy(tmpteam,arrdetails[z+1].team);
tmpplayed=arrdetails[z+1].played;
tmppoints=arrdetails[z+1].points;
tmpgoalsf=arrdetails[z+1].goalsf;
tmpgoalsa=arrdetails[z+1].goalsa;
strcpy(arrdetails[z+1].team,arrdetails[z].team);
arrdetails[z+1].played=arrdetails[z].played;
arrdetails[z+1].points=arrdetails[z].points;
arrdetails[z+1].goalsf=arrdetails[z].goalsf;
arrdetails[z+1].goalsa=arrdetails[z].goalsa;
strcpy(arrdetails[z].team,tmpteam);
arrdetails[z].played=tmpplayed;
arrdetails[z].points=tmppoints;
arrdetails[z].goalsf=tmpgoalsf;
arrdetails[z].goalsa=tmpgoalsa;
z--;
}
}
}
}
void sort_alpha (void)
{
int z;
int j;
char tmpteam[20];
int tmpplayed;
int tmppoints;
int tmpgoalsf;
int tmpgoalsa;
int i ;
if (strcmp(arrdetails[z].team, arrdetails[z+1].team ))
{
i = -1;
strcpy(tmpteam,arrdetails[z+1].team);
tmpplayed=arrdetails[z+1].played;
tmppoints=arrdetails[z+1].points;
tmpgoalsf=arrdetails[z+1].goalsf;
tmpgoalsa=arrdetails[z+1].goalsa;
strcpy(arrdetails[z+1].team,arrdetails[z].team);
arrdetails[z+1].played=arrdetails[z].played;
arrdetails[z+1].points=arrdetails[z].points;
arrdetails[z+1].goalsf=arrdetails[z].goalsf;
arrdetails[z+1].goalsa=arrdetails[z].goalsa;
strcpy(arrdetails[z].team, arrdetails[j].team);
arrdetails[z].played=arrdetails[j].played;
arrdetails[z].points=arrdetails[j].points;
arrdetails[z].goalsf=arrdetails[j].goalsf;
arrdetails[z].goalsa=arrdetails[j].goalsa;
}
else
{
i = 1;
}
}
void draw_sorted (void)
{
printf("\nAFTER INSERTION SORT\n");
printf("\t\t\tPlayed\tPoints\tGoals for\tGoals against\n");
printf("\n");
printf("%s \t %d \t %d \t %d \t \t %d\n",arrdetails[7].team,arrdetails[7].played,arrdetails[7].points,arrdetails[7].goalsf,arrdetails[7].goalsa);
printf("%s \t\t %d \t %d \t %d \t \t %d\n",arrdetails[6].team,arrdetails[6].played,arrdetails[6].points,arrdetails[6].goalsf,arrdetails[6].goalsa);
printf("%s \t\t %d \t %d \t %d \t \t %d\n",arrdetails[5].team,arrdetails[5].played,arrdetails[5].points,arrdetails[5].goalsf,arrdetails[5].goalsa);
printf("%s \t %d \t %d \t %d \t \t %d\n",arrdetails[4].team,arrdetails[4].played,arrdetails[4].points,arrdetails[4].goalsf,arrdetails[4].goalsa);
printf("%s \t\t %d \t %d \t %d \t \t %d\n",arrdetails[3].team,arrdetails[3].played,arrdetails[3].points,arrdetails[3].goalsf,arrdetails[3].goalsa);
printf("%s \t\t\t %d \t %d \t %d \t \t %d\n",arrdetails[2].team,arrdetails[2].played,arrdetails[2].points,arrdetails[2].goalsf,arrdetails[2].goalsa);
printf("%s \t\t %d \t %d \t %d \t \t %d\n",arrdetails[1].team,arrdetails[1].played,arrdetails[1].points,arrdetails[1].goalsf,arrdetails[1].goalsa);
printf("%s \t\t\t %d \t %d \t %d \t \t %d\n",arrdetails[0].team,arrdetails[0].played,arrdetails[0].points,arrdetails[0].goalsf,arrdetails[0].goalsa);
}
thanks everyone