ootball league table - add data

Reply

Join Date: Mar 2007
Posts: 12
Reputation: fightfox06 is an unknown quantity at this point 
Solved Threads: 0
fightfox06 fightfox06 is offline Offline
Newbie Poster

ootball league table - add data

 
0
  #1
Mar 4th, 2007
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....

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #define MAX 8
  5. #define TRUE 1
  6. #define FALSE 0
  7.  
  8. void prior_insertion(void);
  9.  
  10. void draw_table (void);
  11. void insertion_sort (void);
  12. void draw_sorted (void);
  13. void gfor_against (void);
  14. void sort_alpha (void);
  15.  
  16.  
  17. struct
  18. {
  19. char team[20];
  20. int played;
  21. int points;
  22. int goalsf;
  23. int goalsa;
  24. int goalsd;
  25. }arrdetails[8];
  26.  
  27. main()
  28. {
  29. prior_insertion();
  30. draw_table();
  31. insertion_sort();
  32. gfor_against();
  33. sort_alpha();
  34. draw_sorted ();
  35.  
  36. }
  37.  
  38. void prior_insertion(void)
  39.  
  40. {
  41. /*teams*/
  42. strcpy(arrdetails[0].team,"Stoke City");
  43. strcpy(arrdetails[1].team,"Manchester City");
  44. strcpy(arrdetails[2].team,"Port Vale");
  45. strcpy(arrdetails[3].team,"Derby County");
  46. strcpy(arrdetails[4].team,"Birmingham Town");
  47. strcpy(arrdetails[5].team,"Crystal Palace");
  48. strcpy(arrdetails[6].team,"Luton");
  49. strcpy(arrdetails[7].team,"Hull City");
  50.  
  51. /*played*/
  52. arrdetails[0].played=3;
  53. arrdetails[1].played=3;
  54. arrdetails[2].played=3;
  55. arrdetails[3].played=3;
  56. arrdetails[4].played=3;
  57. arrdetails[5].played=3;
  58. arrdetails[6].played=3;
  59. arrdetails[7].played=3;
  60.  
  61. /*points*/
  62. arrdetails[0].points=5;
  63. arrdetails[1].points=3;
  64. arrdetails[2].points=1;
  65. arrdetails[3].points=9;
  66. arrdetails[4].points=7;
  67. arrdetails[5].points=5;
  68. arrdetails[6].points=1;
  69. arrdetails[7].points=1;
  70.  
  71. /*goalsfor*/
  72. arrdetails[0].goalsf=4;
  73. arrdetails[1].goalsf=5;
  74. arrdetails[2].goalsf=2;
  75. arrdetails[3].goalsf=7;
  76. arrdetails[4].goalsf=4;
  77. arrdetails[5].goalsf=4;
  78. arrdetails[6].goalsf=0;
  79. arrdetails[7].goalsf=0;
  80.  
  81. /*goalsagainst*/
  82. arrdetails[0].goalsa=3;
  83. arrdetails[1].goalsa=6;
  84. arrdetails[2].goalsa=6;
  85. arrdetails[3].goalsa=2;
  86. arrdetails[4].goalsa=2;
  87. arrdetails[5].goalsa=3;
  88. arrdetails[6].goalsa=2;
  89. arrdetails[7].goalsa=2;
  90. }
  91.  
  92.  
  93. void draw_table (void)
  94. {
  95. printf("BELOW IS BEFORE AN INSERTION SORT\n");
  96. printf("\t\t\tPlayed\tPoints\tGoals for\tGoals against\n");
  97. printf("\n");
  98. 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);
  99. 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);
  100. 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);
  101. 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);
  102. 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);
  103. 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);
  104. 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);
  105. 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);
  106. }
  107.  
  108. void insertion_sort (void)
  109. {
  110. int pinsert;
  111. int temp;
  112. int z,i,in,gap;
  113. int value;
  114. char tmpteam[20];
  115. int tmpplayed;
  116. int tmppoints;
  117. int tmpgoalsf;
  118. int tmpgoalsa;
  119. z = 0;
  120.  
  121. value=0;
  122.  
  123. for (z = 0; z < MAX; z++)
  124. {
  125. while (arrdetails[z].points > arrdetails[z + 1].points)
  126. {
  127. strcpy(tmpteam,arrdetails[z+1].team);
  128. tmpplayed=arrdetails[z+1].played;
  129. tmppoints=arrdetails[z+1].points;
  130. tmpgoalsf=arrdetails[z+1].goalsf;
  131. tmpgoalsa=arrdetails[z+1].goalsa;
  132.  
  133. strcpy(arrdetails[z+1].team,arrdetails[z].team);
  134. arrdetails[z+1].played=arrdetails[z].played;
  135. arrdetails[z+1].points=arrdetails[z].points;
  136. arrdetails[z+1].goalsf=arrdetails[z].goalsf;
  137. arrdetails[z+1].goalsa=arrdetails[z].goalsa;
  138.  
  139. strcpy(arrdetails[z].team,tmpteam);
  140. arrdetails[z].played=tmpplayed;
  141. arrdetails[z].points=tmppoints;
  142. arrdetails[z].goalsf=tmpgoalsf;
  143. arrdetails[z].goalsa=tmpgoalsa;
  144.  
  145. z--;
  146. }
  147. }
  148. }
  149.  
  150. void gfor_against (void)
  151. {
  152. int value,z,i,gap,in,x;
  153. char tmpteam[20];
  154. int tmpplayed;
  155. int tmppoints;
  156. int tmpgoalsf;
  157. int tmpgoalsa;
  158. int alpha;
  159. x = 0;
  160.  
  161. for (z = 0; z < MAX; z++)/*work out the goals difference*/
  162. {
  163. arrdetails[z].goalsd=arrdetails[z].goalsf-arrdetails[z].goalsa;
  164. }
  165.  
  166. for (z = 0; z < MAX; z++)
  167. {
  168. if(arrdetails[z].points == arrdetails[z+1].points)
  169. {
  170. while (arrdetails[z].goalsd > arrdetails[z + 1].goalsd)
  171. {
  172. strcpy(tmpteam,arrdetails[z+1].team);
  173. tmpplayed=arrdetails[z+1].played;
  174. tmppoints=arrdetails[z+1].points;
  175. tmpgoalsf=arrdetails[z+1].goalsf;
  176. tmpgoalsa=arrdetails[z+1].goalsa;
  177.  
  178. strcpy(arrdetails[z+1].team,arrdetails[z].team);
  179. arrdetails[z+1].played=arrdetails[z].played;
  180. arrdetails[z+1].points=arrdetails[z].points;
  181. arrdetails[z+1].goalsf=arrdetails[z].goalsf;
  182. arrdetails[z+1].goalsa=arrdetails[z].goalsa;
  183.  
  184. strcpy(arrdetails[z].team,tmpteam);
  185. arrdetails[z].played=tmpplayed;
  186. arrdetails[z].points=tmppoints;
  187. arrdetails[z].goalsf=tmpgoalsf;
  188. arrdetails[z].goalsa=tmpgoalsa;
  189.  
  190. z--;
  191. }
  192. }
  193. }
  194. }
  195.  
  196.  
  197. void sort_alpha (void)
  198. {
  199. int z;
  200. int j;
  201. char tmpteam[20];
  202. int tmpplayed;
  203. int tmppoints;
  204. int tmpgoalsf;
  205. int tmpgoalsa;
  206. int i ;
  207.  
  208. if (strcmp(arrdetails[z].team, arrdetails[z+1].team ))
  209. {
  210. i = -1;
  211. strcpy(tmpteam,arrdetails[z+1].team);
  212. tmpplayed=arrdetails[z+1].played;
  213. tmppoints=arrdetails[z+1].points;
  214. tmpgoalsf=arrdetails[z+1].goalsf;
  215. tmpgoalsa=arrdetails[z+1].goalsa;
  216.  
  217. strcpy(arrdetails[z+1].team,arrdetails[z].team);
  218. arrdetails[z+1].played=arrdetails[z].played;
  219. arrdetails[z+1].points=arrdetails[z].points;
  220. arrdetails[z+1].goalsf=arrdetails[z].goalsf;
  221. arrdetails[z+1].goalsa=arrdetails[z].goalsa;
  222.  
  223. strcpy(arrdetails[z].team, arrdetails[j].team);
  224. arrdetails[z].played=arrdetails[j].played;
  225. arrdetails[z].points=arrdetails[j].points;
  226. arrdetails[z].goalsf=arrdetails[j].goalsf;
  227. arrdetails[z].goalsa=arrdetails[j].goalsa;
  228. }
  229.  
  230. else
  231. {
  232. i = 1;
  233. }
  234.  
  235.  
  236.  
  237.  
  238. }
  239.  
  240. void draw_sorted (void)
  241. {
  242.  
  243. printf("\nAFTER INSERTION SORT\n");
  244. printf("\t\t\tPlayed\tPoints\tGoals for\tGoals against\n");
  245. printf("\n");
  246. 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);
  247. 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);
  248. 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);
  249. 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);
  250. 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);
  251. 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);
  252. 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);
  253. 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);
  254. }

thanks everyone
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: ootball league table - add data

 
0
  #2
Mar 4th, 2007
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:


Originally Posted by fightfox06 View Post
ok need a bit of help.
Good, that's what we're here for...

Originally Posted by fightfox06 View Post
just tryin to figure a way to add scores and that from there,
Huh? What's that mean?

Originally Posted by fightfox06 View Post
also the display code seems a bit messy anyway i can put it into a incremental loop?
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 12
Reputation: fightfox06 is an unknown quantity at this point 
Solved Threads: 0
fightfox06 fightfox06 is offline Offline
Newbie Poster

Re: ootball league table - add data

 
0
  #3
Mar 4th, 2007
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
Last edited by fightfox06; Mar 4th, 2007 at 2:54 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: ootball league table - add data

 
0
  #4
Mar 4th, 2007
Originally Posted by fightfox06 View Post
...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
Taking one step at a time is the best way to program...

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
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 12
Reputation: fightfox06 is an unknown quantity at this point 
Solved Threads: 0
fightfox06 fightfox06 is offline Offline
Newbie Poster

Re: ootball league table - add data

 
0
  #5
Mar 4th, 2007
so if i add sommate along the lines of
  1. main()
  2. {
  3. char option, rtn;
  4. option = print_header();
  5. while(option != 'q' && option != 'Q')
  6. {
  7. switch(option)
  8. {
  9. case 'a': case 'A': /*Enter team */
  10. printf("\nPlease Enter a new team:\n");
  11. break;
  12. case 'b': case'B': /*Display table*/
  13. printf("\nLeague Table:\n");
  14. break;
  15. case 'c': case'C': /*Match details*/
  16. printf("\nLeague Table:\n");
  17. break;
  18. case 'd': case 'D': /*Exit*/
  19. printf("\n*** FINISHED ***\n");
  20. exit(0);
  21. default: /*invalid option letter entererd*/
  22. printf("\nInvalid choice, Please try again\n");
  23. }
  24. option = print_header();
  25. }
  26. return 0;
  27. }

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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: ootball league table - add data

 
0
  #6
Mar 5th, 2007
Close....
  1. main() /**** main is an INT ****/
  2. {
  3. char option, rtn;
  4. option = print_header();
  5. while(option != 'q' && option != 'Q')
  6. {
  7. /**** display your menu ****/
  8. /**** accept option ****/
  9. switch(option)
  10. {
  11. case 'a': case 'A': /*Enter team */
  12. printf("\nPlease Enter a new team:\n");
  13. break;
  14. case 'b': case'B': /*Display table*/
  15. printf("\nLeague Table:\n");
  16. break;
  17. case 'c': case'C': /*Match details*/
  18. printf("\nLeague Table:\n");
  19. break;
  20. case 'd': case 'D': /*Exit*/
  21. printf("\n*** FINISHED ***\n");
  22. exit(0);
  23. default: /*invalid option letter entererd*/
  24. printf("\nInvalid choice, Please try again\n");
  25. }
  26. option = print_header();
  27. }
  28. return 0;
  29. }
In each 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
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 12
Reputation: fightfox06 is an unknown quantity at this point 
Solved Threads: 0
fightfox06 fightfox06 is offline Offline
Newbie Poster

Re: ootball league table - add data

 
0
  #7
Mar 5th, 2007
so how would i go about pointing for example case C to the function

  1.  
  2. void draw_sorted (void)

so that when b is pressed the table it displayed??
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: ootball league table - add data

 
0
  #8
Mar 5th, 2007
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:

  1. //Just gave a name to your struct..
  2. struct TeamInfo
  3. {
  4. char team[20];
  5. int played;
  6. int points;
  7. int goalsf;
  8. int goalsa;
  9. int goalsd;
  10. } ;
  11.  
  12. #define MAX_ALLOWED_TEAMS 20
  13. struct TeamInfo arrdetails[MAX_ALLOWED_TEAMS] ;
  14. int current_empty_slot = 0 ;
  15.  
  16. void take_team_input() ;
  17.  
  18. main() /**** main is an INT ****/
  19. {
  20. //...........
  21. while(option != 'q' && option != 'Q')
  22. {
  23. //...........
  24. switch(option)
  25. {
  26. //...........
  27. case 'c': case'C': /*Take match details input*/
  28. //just call the function that does what you want in this case..
  29. take_team_input() ;
  30. break;
  31. //...........
  32. }
  33. option = print_header();
  34. }
  35. return 0;
  36. }
  37.  
  38. void take_team_input()
  39. {
  40. char choice = 'Y' ;
  41.  
  42. if( MAX_ALLOWED_TEAMS <= current_empty_slot )
  43. {
  44. printf( "\nMax limit for team entries reached.", ) ;
  45. return ;
  46. }
  47.  
  48. while( ('y' == choice) || ('Y' == choice) )
  49. {
  50. //take the input:
  51. printf("\nTaking input for team number: %d", current_empty_slot ) ;
  52. printf("\nEnter team name: ") ; fflush(null) ;
  53. scanf( "%s", arrdetails[current_empty_slot].team ) ;
  54. printf("\nEnter number of games played: ") ; fflush(null) ;
  55. scanf( "%d", arrdetails[current_empty_slot].played ) ;
  56. printf("\nEnter goals for: ") ; fflush(null) ;
  57. scanf( "%d", arrdetails[current_empty_slot].goalsf ) ;
  58. //...... and so on...
  59. //now ask if he wants to enter any more...
  60. printf("\n\nWant to enter details for any more teams? [y/n]: ") ; fflush(null) ;
  61. scanf( "%c", choice ) ;
  62.  
  63. current_empty_slot++ :
  64. }
  65. }

"fflush(null) ;" isn't really mandatory, but lotsa ppl come back quoting problems with printf+scanf usage so...
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: ootball league table - add data

 
0
  #9
Mar 5th, 2007
Originally Posted by thekashyap View Post
"fflush(null) ;" isn't really mandatory, but lotsa ppl come back quoting problems with printf+scanf usage so...
Even more ppl come back yelling at anyone that uses it improperly like this, too. 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
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 12
Reputation: fightfox06 is an unknown quantity at this point 
Solved Threads: 0
fightfox06 fightfox06 is offline Offline
Newbie Poster

Re: ootball league table - add data

 
0
  #10
Mar 5th, 2007
so what do i need to use instead of the fflush(null); line??
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC