AshfaqFardin

Football Game

Aug 1st, 2021
955
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct goals{
  6.     int teamNum;
  7.     int playerId;
  8.    
  9.     void setGoalInfo(){
  10.         cout << "Enter Team Number: ";
  11.         cin >> teamNum;
  12.         teamNum = teamNum - 1; //array indexing
  13.         cout << "Enter Player Id: ";
  14.         cin >> playerId;
  15.         playerId = playerId - 1; //array indexing
  16.     }
  17.    
  18. };
  19.  
  20. void teamWin(int goalsA, int goalsB){
  21.     cout << "Total goals of Team-1: " << goalsA << endl;
  22.     cout << "Total goals of Team-2: " << goalsB << endl;
  23.     if(goalsA > goalsB){
  24.         cout << "Team-1 won the game!" << endl;
  25.     }
  26.     else{
  27.         cout << "Team-2 won the game!" << endl;
  28.     }
  29. }
  30.  
  31. int main()
  32. {
  33.     int** team = new int*[2]; //2 teams
  34.     for(int i = 0; i < 2; i++){
  35.         team[i] = new int[10]; // 2d dynamic array size[2][10];
  36.     }
  37.    
  38.     // initialization
  39.     for(int i = 0; i < 2; i++){
  40.         for(int j = 0; j < 10; j++){
  41.             team[i][j] = 0;
  42.         }
  43.     }
  44.    
  45.     goals firstGoal;
  46.     firstGoal.setGoalInfo();
  47.     team[firstGoal.teamNum][firstGoal.playerId]++; //counting goals;
  48.    
  49.     goals secondGoal;
  50.     secondGoal.setGoalInfo();
  51.     team[secondGoal.teamNum][secondGoal.playerId]++; //counting goals;
  52.    
  53.     goals thirdGoal;
  54.     thirdGoal.setGoalInfo();
  55.     team[thirdGoal.teamNum][thirdGoal.playerId]++; //counting goals;
  56.    
  57.     goals fourthGoal;
  58.     fourthGoal.setGoalInfo();
  59.     team[fourthGoal.teamNum][fourthGoal.playerId]++; //counting goals;
  60.    
  61.     goals fifthGoal;
  62.     fifthGoal.setGoalInfo();
  63.     team[fifthGoal.teamNum][fifthGoal.playerId]++; //counting goals;
  64.    
  65.     for(int i = 0; i < 2; i++){
  66.         cout << "Team " << i + 1 << endl;
  67.         cout << "Player ID :";
  68.         for(int j = 0; j < 10; j++){
  69.             cout << j + 1 << " ";
  70.         }
  71.        
  72.         cout << endl;
  73.         cout << "Goals:     ";
  74.         for(int k = 0; k < 10; k++){
  75.             cout << team[i][k] << " ";
  76.         }
  77.         cout << endl;
  78.     }
  79.    
  80.     //winning team decide
  81.     int countGoalsA = 0;
  82.     int countGoalsB = 0;
  83.     for(int i = 0; i < 10; i++){
  84.         if(team[0][i] == 1){
  85.             countGoalsA++;
  86.         }
  87.         if(team[1][i] == 1){
  88.             countGoalsB++;
  89.         }
  90.     }
  91.    
  92.     teamWin(countGoalsA, countGoalsB);
  93.  
  94.     return 0;
  95. }
  96.  
RAW Paste Data