Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define NUMTEAMS 4
- #define NUMMATCHES 6
- void setMatch(int* matches, int team1, int team2);
- bool isValidMachisValidMach(int* matches, int team1, int team2);
- int main() {
- int favorite_team = 0;
- cout << "which is your favorite team? (1, 2, 3, or 4)" << endl;
- cin >> favorite_team;
- while(favorite_team < 1 || favorite_team > 4) {
- cout << "the number you gave is out of range" << endl;
- cout << " which is your favorite team? (1, 2, 3, or 4)" << endl;
- cin >> favorite_team;
- }
- int num_games_already_played = 0;
- cout << "how many games have already been played? (0-5)" << endl;
- cin >> num_games_already_played;
- while(num_games_already_played < 0 || num_games_already_played > 5) {
- cout << "the number you gave is out of range" << endl;
- cout << "how many games have already been played? (0-5)" << endl;
- cin >> num_games_already_played;
- }
- int team_points[NUMTEAMS];
- for(int i = 0; i < NUMTEAMS; i++) {
- team_points[i] = 0;
- }
- int matches[NUMMATCHES];
- for(int i = 0; i < NUMMATCHES; i++) {
- matches[i] = 0;
- }
- for(int i = 0; i < num_games_already_played; i++) {
- cout << "enter the game results for game " << i + 1 << endl;
- cout << "([first team] [second team] [first team score] [second team score])" << endl;
- int team1 = 0;
- int team2 = 0;
- int team1_score = 0;
- int team2_score = 0;
- cin >> team1;
- cin >> team2;
- cin >> team1_score;
- cin >> team2_score;
- bool valid_team_input = (team1 >= 1 && team1 <= 4 && team2 >= 1 && team2 <= 4 && team1 < team2);
- bool valid_team_score_input = (team1_score >= 0 && team2_score >= 0);
- bool valid_match = isValidMach(matches, team1, team2);
- while(!valid_team_input || !valid_team_score_input || !valid_match) {
- cout << "invalid input, please re-enter the game results for game " << i + 1 << endl;
- cout << "([first team] [second team] [first team score] [second team score])" << endl;
- cin >> team1;
- cin >> team2;
- cin >> team1_score;
- cin >> team2_score;
- valid_team_input = (team1 >= 1 && team1 <= 4 && team2 >= 1 && team2 <= 4 && team1 < team2);
- valid_team_score_input = (team1_score >= 0 && team2_score >= 0);
- valid_match = isValidMach(matches, team1, team2);
- }
- if(team1_score > team2_score) {
- team_points[team1] += 3;
- team_points[team2] += 0;
- }
- else if(team2_score > team1_score) {
- team_points[team1] += 0;
- team_points[team2] += 3;
- }
- else { //tie
- team_points[team1] += 1;
- team_points[team2] += 1;
- }
- setMatch(matches, team1, team2);
- }
- int num_games_left = 6 - num_games_already_played;
- //possible_outcomes == 3 to the power of num_games_left (3 possible outcomes per game for the number of games left)
- int possible_outcomes = 0;
- for(int i = 0; i < num_games_left; i++) {
- possible_outcomes *= 3;
- }
- //calculate outcomes in which x team wins
- return 0;
- }
- void setMatch(int* matches, int team1, int team2) {
- if(team1 == 1) {
- if(team2 == 2) {
- matches[0] = 1;
- }
- else if(team2 == 3) {
- matches[1] = 1;
- }
- else { //team2 == 4
- matches[2] = 1;
- }
- }
- else if(team1 == 2) {
- if(team2 == 3) {
- matches[3] = 1;
- }
- else { //team2 == 4
- matches[4] = 1;
- }
- }
- else { //team1 == 3
- matches[5] = 1;
- }
- bool isValidMach(int* matches, int team1, int team2) {
- if(team1 == 1) {
- if(team2 == 2) {
- return matches[0] == 0;
- }
- else if(team2 == 3) {
- return matches[1] == 0;
- }
- else { //team2 == 4
- return matches[2] == 0;
- }
- }
- else if(team1 == 2) {
- if(team2 == 3) {
- return matches[3] == 0;
- }
- else { //team2 == 4
- return matches[4] == 0;
- }
- }
- else { //team1 == 3
- return matches[5] == 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement