Question

Create a struct for a baseball player. Include the player's Name (string), Batting Average (percentage), Home...

Create a struct for a baseball player. Include the player's

Name (string), Batting Average (percentage), Home Runs (int), RBI's (int), Runs Scored (int), Stolen bases (int),
current salary (float) and current team (string).

Create three players using your struct and then display the stats from each player to the screen using the members of the struct- three extra credit points for doing this for all members of the struct in a function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>

struct player {
        char name[50];
        float bat_avg;
        int home_run;
        int rbi;
        int run_scored;
        int stolen_base;
        float current_salary;
        char current_team[50];
};
void display(struct player x) {
        printf("Name : %s\n", x.name);
        printf("Batting average : %f\n", x.bat_avg);
        printf("Home runs : %d\n", x.home_run);
        printf("RBI's : %d\n", x.rbi);
        printf("Runs Scored : %d\n", x.run_scored);
        printf("Stolen bases : %d\n", x.stolen_base);
        printf("Current Salary: %f\n", x.current_salary);
        
        printf("Current team: %s\n", x.current_team);
}
int main() {
        struct player p1, p2, p3;
        strcpy(p1.name , "Andy Robbin");
        p1.bat_avg = 30.65;
        p1.home_run = 2000;
        p1.rbi = 10;
        p1.run_scored = 3000;
        p1.stolen_base = 23;
        p1.current_salary = 10000.20;
        strcpy(p1.current_team, "Team 1");

        strcpy(p2.name, "Steve");
        p2.bat_avg = 20.99;
        p2.home_run = 1574;
        p2.rbi = 7;
        p2.run_scored = 3500;
        p2.stolen_base = 50;
        p2.current_salary = 5000.56;
        strcpy(p2.current_team, "Team 2");

        strcpy(p3.name, "Brian Daniels");
        p3.bat_avg = 42.32;
        p3.home_run = 5000;
        p3.rbi = 12;
        p3.run_scored = 5000;
        p3.stolen_base = 17;
        p3.current_salary = 7000;
        strcpy(p3.current_team, "Team 3");

        display(p1);
        display(p2);
        display(p3);
        getch();
        return 0;
}
Add a comment
Know the answer?
Add Answer to:
Create a struct for a baseball player. Include the player's Name (string), Batting Average (percentage), Home...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT