Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. // Written by Jacob
  2. // The purpose of this program is to input the wins of three teams and then have them arranged from 1st to 3rd place.
  3. // This is a first year Comp Sci assignment
  4.  
  5. #include <stdio.h>
  6.  
  7. int main()
  8. {
  9.  
  10. //Declare variables
  11. int guelphWins, vanWins, vicWins, error;
  12. int guelphLosses, vanLosses, vicLosses;
  13. int guelphPlace, vanPlace, vicPlace;
  14. int firstWins, secondWins, thirdWins;
  15. int firstLosses, secondLosses, thirdLosses;
  16. char first[6], second[6], third[6];
  17.  
  18. error = 0;
  19.  
  20. printf("Input the wins for Guelph:");
  21. scanf("%d", &guelphWins);
  22.  
  23. if((guelphWins < 0) || (guelphWins > 10)) error = 1;
  24. guelphLosses = 10 - guelphWins;
  25.  
  26. printf("Input the wins for Vancouver:");
  27. scanf("%d", &vanWins);
  28.  
  29. if((vanWins < 0) || (vanWins > 10)) error = 1;
  30. vanLosses = 10 - vanWins;
  31.  
  32. printf("Input the wins for Victoria:");
  33. scanf("%d", &vicWins);
  34.  
  35. if((vicWins < 0) || (vicWins > 10)) error = 1;
  36. vicLosses = 10 - vicWins;
  37.  
  38. if((guelphWins + vanWins + vicWins) != 15) error = 1;
  39. if((guelphLosses + vanLosses + vicLosses) != 15) error = 1;
  40.  
  41.  
  42. guelphPlace = 1;
  43. vanPlace = 1;
  44. vicPlace = 1;
  45.  
  46. //Finding what place everyone is in
  47. if(vanWins > guelphWins) guelphPlace += 1;
  48. else vanPlace += 1;
  49.  
  50. if(vanWins > vicWins) vicPlace += 1;
  51. else vanPlace += 1;
  52.  
  53. if(vicWins > guelphWins) guelphPlace += 1;
  54. else vicPlace += 1;
  55.  
  56. //Setting the places
  57. if(guelphPlace == 1) {
  58. first[1] = 'G';
  59. first[2] = 'u';
  60. first[3] = 'e';
  61. first[4] = 'l';
  62. first[5] = 'p';
  63. first[6] = 'h';
  64. firstWins = guelphWins;
  65. firstLosses = guelphLosses;
  66. } else {
  67. if(vanPlace == 1) {
  68. first[1] = 'V';
  69. first[2] = 'a';
  70. first[3] = 'n';
  71. first[4] = ' ';
  72. first[5] = ' ';
  73. first[6] = ' ';
  74. firstWins = vanWins;
  75. firstLosses = vanLosses;
  76. } else {
  77. first[1] = 'V';
  78. first[2] = 'i';
  79. first[3] = 'c';
  80. first[4] = ' ';
  81. first[5] = ' ';
  82. first[6] = ' ';
  83. firstWins = vicWins;
  84. firstLosses = vicLosses;
  85. }
  86. }
  87.  
  88. if(guelphPlace == 2) {
  89. second[1] = 'G';
  90. second[2] = 'u';
  91. second[3] = 'e';
  92. second[4] = 'l';
  93. second[5] = 'p';
  94. second[6] = 'h';
  95. secondWins = guelphWins;
  96. secondLosses = guelphLosses;
  97. } else {
  98. if(vicPlace == 2) {
  99. second[1] = 'V';
  100. second[2] = 'i';
  101. second[3] = 'c';
  102. second[4] = ' ';
  103. second[5] = ' ';
  104. second[6] = ' ';
  105. secondWins = vicWins;
  106. secondLosses = vicLosses;
  107. } else {
  108. second[1] = 'V';
  109. second[2] = 'a';
  110. second[3] = 'n';
  111. second[4] = ' ';
  112. second[5] = ' ';
  113. second[6] = ' ';
  114. secondWins = vanWins;
  115. secondLosses = vanLosses;
  116. }
  117. }
  118.  
  119. if(guelphPlace == 3) {
  120. third[1] = 'G';
  121. third[2] = 'u';
  122. third[3] = 'e';
  123. third[4] = 'l';
  124. third[5] = 'p';
  125. third[6] = 'h';
  126. thirdWins = guelphWins;
  127. thirdLosses = guelphLosses;
  128. } else {
  129. if(vanPlace == 3) {
  130. third[1] = 'V';
  131. third[2] = 'a';
  132. third[3] = 'n';
  133. third[4] = ' ';
  134. third[5] = ' ';
  135. third[6] = ' ';
  136. thirdWins = vanWins;
  137. thirdLosses = vanLosses;
  138. } else {
  139. third[1] = 'V';
  140. third[2] = 'i';
  141. third[3] = 'c';
  142. third[4] = ' ';
  143. third[5] = ' ';
  144. third[6] = ' ';
  145. thirdWins = vicWins;
  146. thirdLosses = vicLosses;
  147. }
  148. }
  149. printf("8 %d %d %d %d\n", vicWins, firstWins, secondWins, thirdWins);
  150. if(error == 0) {
  151. printf("------------------------------\n");
  152. printf("Place Team Wins Losses\n");
  153. printf("------------------------------\n");
  154. 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);
  155. 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);
  156. 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);
  157. 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);
  158. 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);
  159. printf("------------------------------\n");
  160. } else printf("The scores entered were invalid\n");
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement