Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Written by Jacob
- // The purpose of this program is to input the wins of three teams and then have them arranged from 1st to 3rd place.
- // This is a first year Comp Sci assignment
- #include <stdio.h>
- int main()
- {
- //Declare variables
- int guelphWins, vanWins, vicWins, error;
- int guelphLosses, vanLosses, vicLosses;
- int guelphPlace, vanPlace, vicPlace;
- int firstWins, secondWins, thirdWins;
- int firstLosses, secondLosses, thirdLosses;
- char first[6], second[6], third[6];
- error = 0;
- printf("Input the wins for Guelph:");
- scanf("%d", &guelphWins);
- if((guelphWins < 0) || (guelphWins > 10)) error = 1;
- guelphLosses = 10 - guelphWins;
- printf("Input the wins for Vancouver:");
- scanf("%d", &vanWins);
- if((vanWins < 0) || (vanWins > 10)) error = 1;
- vanLosses = 10 - vanWins;
- printf("Input the wins for Victoria:");
- scanf("%d", &vicWins);
- if((vicWins < 0) || (vicWins > 10)) error = 1;
- vicLosses = 10 - vicWins;
- if((guelphWins + vanWins + vicWins) != 15) error = 1;
- if((guelphLosses + vanLosses + vicLosses) != 15) error = 1;
- guelphPlace = 1;
- vanPlace = 1;
- vicPlace = 1;
- //Finding what place everyone is in
- if(vanWins > guelphWins) guelphPlace += 1;
- else vanPlace += 1;
- if(vanWins > vicWins) vicPlace += 1;
- else vanPlace += 1;
- if(vicWins > guelphWins) guelphPlace += 1;
- else vicPlace += 1;
- //Setting the places
- if(guelphPlace == 1) {
- first[1] = 'G';
- first[2] = 'u';
- first[3] = 'e';
- first[4] = 'l';
- first[5] = 'p';
- first[6] = 'h';
- firstWins = guelphWins;
- firstLosses = guelphLosses;
- } else {
- if(vanPlace == 1) {
- first[1] = 'V';
- first[2] = 'a';
- first[3] = 'n';
- first[4] = ' ';
- first[5] = ' ';
- first[6] = ' ';
- firstWins = vanWins;
- firstLosses = vanLosses;
- } else {
- first[1] = 'V';
- first[2] = 'i';
- first[3] = 'c';
- first[4] = ' ';
- first[5] = ' ';
- first[6] = ' ';
- firstWins = vicWins;
- firstLosses = vicLosses;
- }
- }
- if(guelphPlace == 2) {
- second[1] = 'G';
- second[2] = 'u';
- second[3] = 'e';
- second[4] = 'l';
- second[5] = 'p';
- second[6] = 'h';
- secondWins = guelphWins;
- secondLosses = guelphLosses;
- } else {
- if(vicPlace == 2) {
- second[1] = 'V';
- second[2] = 'i';
- second[3] = 'c';
- second[4] = ' ';
- second[5] = ' ';
- second[6] = ' ';
- secondWins = vicWins;
- secondLosses = vicLosses;
- } else {
- second[1] = 'V';
- second[2] = 'a';
- second[3] = 'n';
- second[4] = ' ';
- second[5] = ' ';
- second[6] = ' ';
- secondWins = vanWins;
- secondLosses = vanLosses;
- }
- }
- if(guelphPlace == 3) {
- third[1] = 'G';
- third[2] = 'u';
- third[3] = 'e';
- third[4] = 'l';
- third[5] = 'p';
- third[6] = 'h';
- thirdWins = guelphWins;
- thirdLosses = guelphLosses;
- } else {
- if(vanPlace == 3) {
- third[1] = 'V';
- third[2] = 'a';
- third[3] = 'n';
- third[4] = ' ';
- third[5] = ' ';
- third[6] = ' ';
- thirdWins = vanWins;
- thirdLosses = vanLosses;
- } else {
- third[1] = 'V';
- third[2] = 'i';
- third[3] = 'c';
- third[4] = ' ';
- third[5] = ' ';
- third[6] = ' ';
- thirdWins = vicWins;
- thirdLosses = vicLosses;
- }
- }
- printf("8 %d %d %d %d\n", vicWins, firstWins, secondWins, thirdWins);
- if(error == 0) {
- printf("------------------------------\n");
- printf("Place Team Wins Losses\n");
- printf("------------------------------\n");
- if(firstWins != 10) printf("1 %c%c%c%c%c%c %d %d\n", first[1], first[2], first[3], first[4], first[5], first[6], firstWins, firstLosses);
- else printf("1 %c%c%c%c%c%c %d %d\n", first[1], first[2], first[3], first[4], first[5], first[6], firstWins, firstLosses);
- printf("2 %c%c%c%c%c%c %d %d\n", second[1], second[2], second[3], second[4], second[5], second[6], secondWins, secondLosses);
- if(thirdLosses != 10) printf("3 %c%c%c%c%c%c %d %d\n", third[1], third[2], third[3], third[4], third[5], third[6], thirdWins, thirdLosses);
- else printf("3 %c%c%c%c%c%c %d %d\n", third[1], third[2], third[3], third[4], third[5], third[6], thirdWins, thirdLosses);
- printf("------------------------------\n");
- } else printf("The scores entered were invalid\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement