Advertisement
Guest User

Untitled

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