Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.91 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #define NUMTEAMS 4
  6. #define NUMMATCHES 6
  7.  
  8. void setMatch(int* matches, int team1, int team2);
  9. bool isValidMachisValidMach(int* matches, int team1, int team2);
  10.  
  11. int main() {
  12.   int favorite_team = 0;
  13.   cout << "which is your favorite team? (1, 2, 3, or 4)" << endl;
  14.   cin >> favorite_team;
  15.   while(favorite_team < 1 || favorite_team > 4) {
  16.     cout << "the number you gave is out of range" << endl;
  17.     cout << " which is your favorite team? (1, 2, 3, or 4)" << endl;
  18.     cin >> favorite_team;
  19.   }
  20.  
  21.   int num_games_already_played = 0;
  22.   cout << "how many games have already been played? (0-5)" << endl;
  23.   cin >> num_games_already_played;
  24.   while(num_games_already_played < 0 || num_games_already_played > 5) {
  25.     cout << "the number you gave is out of range" << endl;
  26.     cout << "how many games have already been played? (0-5)" << endl;
  27.     cin >> num_games_already_played;
  28.   }
  29.  
  30.   int team_points[NUMTEAMS];
  31.   for(int i = 0; i < NUMTEAMS; i++) {
  32.     team_points[i] = 0;
  33.   }
  34.  
  35.   int matches[NUMMATCHES];
  36.   for(int i = 0; i < NUMMATCHES; i++) {
  37.     matches[i] = 0;
  38.   }
  39.  
  40.   for(int i = 0; i < num_games_already_played; i++) {
  41.     cout << "enter the game results for game " << i + 1 << endl;
  42.     cout << "([first team] [second team] [first team score] [second team score])" << endl;
  43.     int team1 = 0;
  44.     int team2 = 0;
  45.     int team1_score = 0;
  46.     int team2_score = 0;
  47.  
  48.     cin >> team1;
  49.     cin >> team2;
  50.     cin >> team1_score;
  51.     cin >> team2_score;
  52.  
  53.     bool valid_team_input = (team1 >= 1 && team1 <= 4 && team2 >= 1 && team2 <= 4 && team1 < team2);
  54.     bool valid_team_score_input = (team1_score >= 0 && team2_score >= 0);
  55.     bool valid_match = isValidMach(matches, team1, team2);
  56.  
  57.     while(!valid_team_input || !valid_team_score_input || !valid_match) {
  58.       cout << "invalid input, please re-enter the game results for game " << i + 1 << endl;
  59.       cout << "([first team] [second team] [first team score] [second team score])" << endl;
  60.  
  61.       cin >> team1;
  62.       cin >> team2;
  63.       cin >> team1_score;
  64.       cin >> team2_score;
  65.  
  66.       valid_team_input = (team1 >= 1 && team1 <= 4 && team2 >= 1 && team2 <= 4 && team1 < team2);
  67.       valid_team_score_input = (team1_score >= 0 && team2_score >= 0);
  68.       valid_match = isValidMach(matches, team1, team2);
  69.     }
  70.  
  71.     if(team1_score > team2_score) {
  72.       team_points[team1] += 3;
  73.       team_points[team2] += 0;
  74.     }
  75.     else if(team2_score > team1_score) {
  76.       team_points[team1] += 0;
  77.       team_points[team2] += 3;
  78.     }
  79.     else { //tie
  80.       team_points[team1] += 1;
  81.       team_points[team2] += 1;
  82.     }
  83.  
  84.     setMatch(matches, team1, team2);
  85.   }
  86.  
  87.   int num_games_left = 6 - num_games_already_played;
  88.  
  89.   //possible_outcomes == 3 to the power of num_games_left (3 possible outcomes per game for the number of games left)
  90.   int possible_outcomes = 0;
  91.   for(int i = 0; i < num_games_left; i++) {
  92.     possible_outcomes *= 3;
  93.   }
  94.  
  95.   //calculate outcomes in which x team wins
  96.  
  97.  
  98.   return 0;
  99. }
  100.  
  101. void setMatch(int* matches, int team1, int team2) {
  102.   if(team1 == 1) {
  103.     if(team2 == 2) {
  104.       matches[0] = 1;
  105.     }
  106.     else if(team2 == 3) {
  107.       matches[1] = 1;
  108.     }
  109.     else { //team2 == 4
  110.       matches[2] = 1;
  111.     }
  112.   }
  113.   else if(team1 == 2) {
  114.     if(team2 == 3) {
  115.       matches[3] = 1;
  116.     }
  117.     else { //team2 == 4
  118.       matches[4] = 1;
  119.     }
  120.   }
  121.   else { //team1 == 3
  122.     matches[5] = 1;
  123. }
  124.  
  125. bool isValidMach(int* matches, int team1, int team2) {
  126.   if(team1 == 1) {
  127.     if(team2 == 2) {
  128.       return matches[0] == 0;
  129.     }
  130.     else if(team2 == 3) {
  131.       return matches[1] == 0;
  132.     }
  133.     else { //team2 == 4
  134.       return matches[2] == 0;
  135.     }
  136.   }
  137.   else if(team1 == 2) {
  138.     if(team2 == 3) {
  139.       return matches[3] == 0;
  140.     }
  141.     else { //team2 == 4
  142.       return matches[4] == 0;
  143.     }
  144.   }
  145.   else { //team1 == 3
  146.     return matches[5] == 0;
  147.   }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement