Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- //Global Structure
- struct Team
- {
- int played;
- int goalsfor;
- int goalsagainst;
- int points;
- };
- int main()
- {
- //Structures
- struct Team teams[7] = {0};
- //Variables
- int Home, Away, Homegoals, Awaygoals;
- int i;
- char choice;
- //Team input
- do
- {
- do
- {
- printf("Home team number: ");
- scanf("%i", &Home);
- --Home;
- printf("Away team number: ");
- scanf("%i", &Away);
- --Away;
- if(Home == Away || Home < 0 || Away < 0)
- {
- printf("Please enter two different positive team numbers.\n");
- }
- } while(Home == Away || Home < 0 || Away < 0);
- //Home Team
- printf("Enter goals scored by Team %d: ", Home + 1);
- scanf_s("%i", &Homegoals);
- while(Homegoals < 0)
- { //Loops till positive number is input
- printf("Enter a positive number: ");
- scanf_s("%i", &Homegoals);
- }
- teams[Home].goalsfor += Homegoals; //Home Goals Adder
- teams[Away].goalsagainst += Homegoals; //Away Goals against adder
- teams[Home].played += 1; //Home Counter
- //Away Team
- printf("Enter goals scored by Team %d: ", Away + 1);
- scanf_s("%d", &Awaygoals);
- while(Awaygoals < 0)
- { //Loops till positive number is input
- printf("Enter a positive number: ");
- scanf_s("%d", &Awaygoals);
- }
- teams[Away].goalsfor += Awaygoals; //Away Goals Adder
- teams[Home].goalsagainst += Awaygoals; //Home Goals against adder
- teams[Away].played++; //Away Counter
- //Points
- if(teams[Home].goalsfor < teams[Away].goalsfor)
- { //Home Wins
- teams[Away].points += 3;
- }
- else if(teams[Home].goalsfor == teams[Away].goalsfor)
- { //Draw
- teams[Home].points++;
- teams[Away].points++;
- }
- else if(teams[Home].goalsfor > teams[Away].goalsfor)
- { // Away Wins
- teams[Home].points += 3;
- }
- //Table
- printf("Team Played For Against Points\n");
- for(i = 0; i < 6; i++)
- {
- printf("Team %i %i %i %i %i\n", i + 1, teams[i].played, teams[i].goalsfor,
- teams[i].goalsagainst, teams[i].points);
- }
- //Exit Sequence
- do
- {
- printf("Exit? (Y/N): ");
- scanf_s(" %c", &choice);
- if(choice == 'y' || choice == 'Y')
- { //Ends Program
- printf("\nProgram ending\n\n");
- break;
- }
- else if(choice == 'n' || choice == 'N')
- { //Continues Program
- break;
- }
- else if(choice != 'y' && choice != 'Y' && choice != 'n' && choice != 'N')
- { //Error Message
- printf("Please enter Y/N\n");
- }
- } while(choice != 'y' && choice != 'Y' && choice != 'n' && choice != 'N');
- } while(choice == 'n' || choice == 'N');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement