Advertisement
Guest User

Untitled

a guest
May 20th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. //Global Structure
  5. struct Team {
  6. int played;
  7. int goalsfor;
  8. int goalsagainst;
  9. int points;
  10. };
  11.  
  12. int main()
  13. {
  14.  
  15. //Structures
  16. struct Team teams[7] = { 0 };
  17.  
  18. //Variables
  19. int Home, Away, Homegoals, Awaygoals;
  20. int i;
  21. char choice;
  22.  
  23. //Team input
  24. do{
  25. do {
  26. printf("Home team number: ");
  27. scanf("%i", &Home);
  28.  
  29. printf("Away team number: ");
  30. scanf("%i", &Away);
  31. if (Home == Away)
  32. {
  33. printf("Please enter two different teams.\n");
  34. }
  35. } while (Home == Away);
  36.  
  37. //Home Team
  38. printf("Enter goals scored by Team %d: ", Home);
  39. scanf_s("%i", &Homegoals);
  40. while (Homegoals < 0) { //Loops till positive number is input
  41. printf("Enter a positive number: ");
  42. scanf_s("%i", &Homegoals);
  43. }
  44. teams[Home - 1].goalsfor += Homegoals; //Home Goals Adder
  45. teams[Away - 1].goalsagainst += Homegoals; //Away Goals against adder
  46. teams[Home-1].played += 1; //Home Counter
  47.  
  48. //Away Team
  49. printf("Enter goals scored by Team %d: ", Away);
  50. scanf_s("%d", &Awaygoals);
  51. while (Awaygoals < 0) { //Loops till positive number is input
  52. printf("Enter a positive number: ");
  53. scanf_s("%d", &Awaygoals);
  54. }
  55. teams[Away - 1].goalsfor += Awaygoals; //Away Goals Adder
  56. teams[Home - 1].goalsagainst += Awaygoals; //Home Goals against adder
  57. teams[Away-1].played += 1; //Away Counter
  58.  
  59. //Points
  60. if (teams[Home - 1].goalsfor < teams[Away - 1].goalsfor) { //Home Wins
  61. teams[Away - 1].points = teams[Away - 1].points + 3;
  62. }
  63. else if (teams[Home - 1].goalsfor == teams[Away - 1].goalsfor) { //Draw
  64. teams[Home - 1].points = teams[Home - 1].points + 1;
  65. teams[Away - 1].points = teams[Away - 1].points + 1;
  66. }
  67. else if (teams[Home - 1].goalsfor > teams[Away - 1].goalsfor) { // Away Wins
  68. teams[Home - 1].points = teams[Home - 1].points + 3;
  69. }
  70.  
  71. //Table
  72. printf("Team Played For Against Points\n");
  73. for (i = 0; i < 6; i++) {
  74. printf("Team %i %i %i %i %i\n", i+1,teams[i].played,teams[i].goalsfor,teams[i].goalsagainst,teams[i].points);
  75. }
  76.  
  77. //Exit Sequence
  78. do {
  79. printf("Exit? (Y/N): ");
  80. scanf_s(" %c", &choice);
  81. if (choice == 'y' || choice == 'Y') { //Ends Program
  82. printf("\nProgram ending\n\n");
  83. break;
  84. }
  85. else if (choice == 'n' || choice == 'N') { //Continues Program
  86. break;
  87. }
  88. else if (choice != 'y' || choice != 'Y' || choice != 'n' || choice != 'N') { //Error Message
  89. printf("Please enter Y/N\n");
  90. }
  91. } while (choice != 'y' || choice != 'Y' || choice != 'n' || choice != 'N');
  92. } while (choice == 'n' || choice == 'N');
  93.  
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement