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);
- printf("Away team number: ");
- scanf("%i", &Away);
- if (Home == Away)
- {
- printf("Please enter two different teams.\n");
- }
- } while (Home == Away);
- //Home Team
- printf("Enter goals scored by Team %d: ", Home);
- scanf_s("%i", &Homegoals);
- while (Homegoals < 0) { //Loops till positive number is input
- printf("Enter a positive number: ");
- scanf_s("%i", &Homegoals);
- }
- teams[Home - 1].goalsfor += Homegoals; //Home Goals Adder
- teams[Away - 1].goalsagainst += Homegoals; //Away Goals against adder
- teams[Home-1].played += 1; //Home Counter
- //Away Team
- printf("Enter goals scored by Team %d: ", Away);
- scanf_s("%d", &Awaygoals);
- while (Awaygoals < 0) { //Loops till positive number is input
- printf("Enter a positive number: ");
- scanf_s("%d", &Awaygoals);
- }
- teams[Away - 1].goalsfor += Awaygoals; //Away Goals Adder
- teams[Home - 1].goalsagainst += Awaygoals; //Home Goals against adder
- teams[Away-1].played += 1; //Away Counter
- //Points
- if (teams[Home - 1].goalsfor < teams[Away - 1].goalsfor) { //Home Wins
- teams[Away - 1].points = teams[Away - 1].points + 3;
- }
- else if (teams[Home - 1].goalsfor == teams[Away - 1].goalsfor) { //Draw
- teams[Home - 1].points = teams[Home - 1].points + 1;
- teams[Away - 1].points = teams[Away - 1].points + 1;
- }
- else if (teams[Home - 1].goalsfor > teams[Away - 1].goalsfor) { // Away Wins
- teams[Home - 1].points = teams[Home - 1].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