Answer to Question #117573 in C for Naim Islam

Question #117573
Create a structure named player where you
have to store the following information of five cricket team players. [Hint : Take input from a text file]
1. Player’s name
2. Player’s country
3. Array(size 2) to store runs of 2 matches
4. Array(size 2) to store wickets of 2 matches
5. Array(size 2) to store points of 2 matches
Count the points using the following formula:
1. Each wicket = 12 points
2. 25 Runs in a match = 5 points
3. 50 Runs in a match = 10 points
4. 75 Runs in a match = 15 points
5. 100 Runs in a match = 20 points

Now Find the Man of the match for the two matches of the series. This is based on the highest point taker in one match. Also find the Man of the series who is the highest point taker in the whole series.
1
Expert's answer
2020-05-24T17:15:30-0400
#include <stdio.h> 
#include <string.h>


struct player{
    char name[20];
    char country[20];
    int run[2];
    int wicket[2];
    int point[2];
};
int main()
{
    int n,points=0; 
    int mom1=0,mos=0,mom2=0;
    char *mom_n1,*mos_n,*mom_n2; 
    
    printf("Enter total number of players played in the tournament: "); 
    scanf("%d",&n);
    struct player p[n];
    printf("Enter Information of %d Players\n",n);
    for(int x=0;x<n;x++){ 
      printf("Information of %d Player\n",x+1);
      printf("Enter Name: ");
      scanf(" %s",p[x].name); 


      printf("Enter country: ");
      scanf("%s",p[x].country); 
      
      printf("Enter Runs of 2 Matches: ");
     for(int i=0;i<2;i++)
        scanf("%d",&p[x].run[i]);
     printf("Enter number of Wickets in 2 Matches: ");
      for(int i=0;i<2;i++)
        scanf("%d",&p[x].wicket[i]);
      printf("Enter points of 2 Matches: ");
      for(int i=0;i<2;i++)
        scanf("%d",&p[x].point[i]); 
      printf("***************************************\n");
      
    }
    for(int i=0;i<n;i++){
      
        points = 0;
        if(50 >p[i].run[0] && p[i].run[0] >= 25)
          points += 5;
        else
          if(75 >p[i].run[0] && p[i].run[0] >= 50)
            points += 10;
          else
            if(100 >p[i].run[0] && p[i].run[0] >= 75)
              points += 15;
            else
              points += 20;
        points += p[i].wicket[0]*12;
        
        if(points > mom1){
          mom1 = points;
          mom_n1 = p[i].name;
        } 
        
        points = 0;
        if(50 >p[i].run[0] && p[i].run[1] >= 25)
          points += 5;
        else
          if(75 >p[i].run[0] && p[i].run[1] >= 50)
            points += 10;
          else
            if(100 >p[i].run[0] && p[i].run[1] >= 75)
              points += 15;
            else
              points += 20;
        points += p[i].wicket[1]*12;
        
        if(points > mom2){
          mom2 = points;
          mom_n2 = p[i].name;
        }
      
      points = 0;
      for(int j=0;j<2;j++){
        if(50 >p[i].run[0] && p[i].run[j] >= 25)
          points += 5;
        else
          if(75 >p[i].run[0] && p[i].run[j] >= 50)
            points += 10;
          else
            if(100 >p[i].run[0] && p[i].run[j] >= 75)
              points += 15;
            else
              points += 20;
        points += p[i].wicket[j]*12;
      }
      if(points > mos){
          mos = points;
          mos_n = p[i].name;
        }
    }
    printf("Man of the Match1: %s with points: %d\n",mom_n1,mom1);
    printf("Man of the Match2: %s with points: %d\n",mom_n2,mom2);
    printf("Man of the Series: %s with points: %d\n",mos_n,mos);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS