| | |
ootball league table - add data
![]() |
•
•
Join Date: Mar 2007
Posts: 12
Reputation:
Solved Threads: 0
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....
thanks everyone
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....
c Syntax (Toggle Plain Text)
#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
Wow!!! First post and you used CODE tags! Thank You. What is it you know that no other first-time poster can figure out? :mrgreen:
Good, that's what we're here for...
Huh? What's that mean?
I suppose...
The code is quite long (obviously) and you give no indication where you need changes. Maybe you need to post only the section of the code you need help with and a better explanation of exactly what you are looking for.
Good, that's what we're here for...
•
•
•
•
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?
The code is quite long (obviously) and you give no indication where you need changes. Maybe you need to post only the section of the code you need help with and a better explanation of exactly what you are looking for.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Mar 2007
Posts: 12
Reputation:
Solved Threads: 0
ok thanks for sayin i can use code tags aint hard reli if i can program in c and java 
so yea that code inputs a football league table and then outputs it unsorted and then sorted.....
...
...
...what i need help with is how would i go about adding a way off adding more data
for example add a game played always one.
points either 0 for a loss, 1 for a draw or 3 for a win, goals scored and goals scored against
want to end up with a menu system and to be able to do all the options below....so far got B and D sorted out just taking things one step at a time
****************************
* Football League *
****************************
A. Add A New Team
B. Display Current Table
C. Enter Match Details
D. Exit System
thanks again

so yea that code inputs a football league table and then outputs it unsorted and then sorted.....
...
...
...what i need help with is how would i go about adding a way off adding more data
for example add a game played always one.
points either 0 for a loss, 1 for a draw or 3 for a win, goals scored and goals scored against
want to end up with a menu system and to be able to do all the options below....so far got B and D sorted out just taking things one step at a time
****************************
* Football League *
****************************
A. Add A New Team
B. Display Current Table
C. Enter Match Details
D. Exit System
thanks again
Last edited by fightfox06; Mar 4th, 2007 at 2:54 pm.
•
•
•
•
...what i need help with is how would i go about adding a way off adding more data
for example add a game played always one.
points either 0 for a loss, 1 for a draw or 3 for a win, goals scored and goals scored against
want to end up with a menu system and to be able to do all the options below....so far got B and D sorted out just taking things one step at a time
****************************
* Football League *
****************************
A. Add A New Team
B. Display Current Table
C. Enter Match Details
D. Exit System
Start with the menu. Put a
while loop in main() that a) displays the menu
b) accept the menu selection
c) executes the appropriate function
d) exits when the EXIT selection is chosen
To add data, do you have a way to store the data for each game won? That would be the first thing. What do you have to save? What are the permissible values? Once you have that, write a function to input the information and load the data.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Mar 2007
Posts: 12
Reputation:
Solved Threads: 0
so if i add sommate along the lines of
sorry for being slow, just not realy good at C java im not soo bad at.
we are doing 3 programming languages this term, C, Java and VB and i dont get C at all. cnt wait till next year when im only doing java
networking is more my cup of tea but we have to do the general route in our 1st year
c Syntax (Toggle Plain Text)
main() { char option, rtn; option = print_header(); while(option != 'q' && option != 'Q') { switch(option) { case 'a': case 'A': /*Enter team */ printf("\nPlease Enter a new team:\n"); break; case 'b': case'B': /*Display table*/ printf("\nLeague Table:\n"); break; case 'c': case'C': /*Match details*/ printf("\nLeague Table:\n"); break; case 'd': case 'D': /*Exit*/ printf("\n*** FINISHED ***\n"); exit(0); default: /*invalid option letter entererd*/ printf("\nInvalid choice, Please try again\n"); } option = print_header(); } return 0; }
sorry for being slow, just not realy good at C java im not soo bad at.
we are doing 3 programming languages this term, C, Java and VB and i dont get C at all. cnt wait till next year when im only doing java
networking is more my cup of tea but we have to do the general route in our 1st year
Last edited by fightfox06; Mar 4th, 2007 at 3:46 pm.
Close....
In each
c Syntax (Toggle Plain Text)
main() /**** main is an INT ****/ { char option, rtn; option = print_header(); while(option != 'q' && option != 'Q') { /**** display your menu ****/ /**** accept option ****/ switch(option) { case 'a': case 'A': /*Enter team */ printf("\nPlease Enter a new team:\n"); break; case 'b': case'B': /*Display table*/ printf("\nLeague Table:\n"); break; case 'c': case'C': /*Match details*/ printf("\nLeague Table:\n"); break; case 'd': case 'D': /*Exit*/ printf("\n*** FINISHED ***\n"); exit(0); default: /*invalid option letter entererd*/ printf("\nInvalid choice, Please try again\n"); } option = print_header(); } return 0; }
case, call a function to process the selection. The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Mar 2007
Posts: 12
Reputation:
Solved Threads: 0
so how would i go about pointing for example case C to the function
so that when b is pressed the table it displayed??
c Syntax (Toggle Plain Text)
void draw_sorted (void)
so that when b is pressed the table it displayed??
I suppose you donno how to use scanf().
As you said you know java let me just say:
System.out.ptintln() = printf()
System.in.read() = scanf()
Here is a sample:
"fflush(null) ;" isn't really mandatory, but lotsa ppl come back quoting problems with printf+scanf usage so...
As you said you know java let me just say:
System.out.ptintln() = printf()
System.in.read() = scanf()
Here is a sample:
c++ Syntax (Toggle Plain Text)
//Just gave a name to your struct.. struct TeamInfo { char team[20]; int played; int points; int goalsf; int goalsa; int goalsd; } ; #define MAX_ALLOWED_TEAMS 20 struct TeamInfo arrdetails[MAX_ALLOWED_TEAMS] ; int current_empty_slot = 0 ; void take_team_input() ; main() /**** main is an INT ****/ { //........... while(option != 'q' && option != 'Q') { //........... switch(option) { //........... case 'c': case'C': /*Take match details input*/ //just call the function that does what you want in this case.. take_team_input() ; break; //........... } option = print_header(); } return 0; } void take_team_input() { char choice = 'Y' ; if( MAX_ALLOWED_TEAMS <= current_empty_slot ) { printf( "\nMax limit for team entries reached.", ) ; return ; } while( ('y' == choice) || ('Y' == choice) ) { //take the input: printf("\nTaking input for team number: %d", current_empty_slot ) ; printf("\nEnter team name: ") ; fflush(null) ; scanf( "%s", arrdetails[current_empty_slot].team ) ; printf("\nEnter number of games played: ") ; fflush(null) ; scanf( "%d", arrdetails[current_empty_slot].played ) ; printf("\nEnter goals for: ") ; fflush(null) ; scanf( "%d", arrdetails[current_empty_slot].goalsf ) ; //...... and so on... //now ask if he wants to enter any more... printf("\n\nWant to enter details for any more teams? [y/n]: ") ; fflush(null) ; scanf( "%c", choice ) ; current_empty_slot++ : } }
"fflush(null) ;" isn't really mandatory, but lotsa ppl come back quoting problems with printf+scanf usage so...
•
•
•
•
"fflush(null) ;" isn't really mandatory, but lotsa ppl come back quoting problems with printf+scanf usage so...
fflush(null); will accomplish nothing at best, break your program at worst. You cannot flush the null device AFAIK. And it is only used for output, never input, streams. See this Last edited by WaltP; Mar 5th, 2007 at 3:52 pm.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Other Threads in the C Forum
- Previous Thread: linked list
- Next Thread: big o notation?
| Thread Tools | Search this Thread |
* adobe ansi api array asterisks binarysearch calculate centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory feet fflush fgets file floatingpointvalidation fork forloop frequency givemetehcodez grade gtkgcurlcompiling gtkwinlinux hacking highest histogram inches input intmain() iso kernel keyboard kilometer km linked linkedlist linux linuxsegmentationfault list locate looping loopinsideloop. lowest match microsoft mqqueue mysql number oddnumber odf opendocumentformat openwebfoundation owf pattern pdf performance posix probleminc process program programming radix recv recvblocked repetition research reversing scanf scheduling segmentationfault sequential single socket socketprograming socketprogramming stack standard string systemcall threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi






