Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can somebody help me refine this program so that it prints numbers in a format t

ID: 3553624 • Letter: C

Question

Can somebody help me refine this program so that it prints numbers in a format that's acceptable in Baseball stats: http://ideone.com/by9v7z


I don't know for example that batting average is supposed to be in the .300 format. I'm struggling on the details here because I don't know anything about Baseball. I just need somebody to check the formulas and print formating so that it would print realistic statistics. Also, the function is supposed to take integers (not doubles) and then return the stats in a structure format.

Explanation / Answer

    #include <stdio.h>
    struct stats
    {
        double base;
        double totalBases;
        double battingAverage;
        double homeRunRatio;
        double sluggingAverage;
    };
    struct stats myBaseBallStats(double singles, double doubles, double triples, double homeRuns, double atBats);   
    struct stats myBaseBallStats(double singles, double doubles, double triples, double homeRuns, double atBats)
    {
        struct stats calc;
        calc.base=50;
        for(int innings=0; innings<calc.base;innings++)
        {
        if(!innings>=4)
        {
        calc.totalBases = (singles + (2 * doubles) + (3 * triples) + (4 * homeRuns));
        calc.battingAverage = (singles + doubles + triples + homeRuns) / atBats;
        calc.homeRunRatio = homeRuns / atBats;
        calc.sluggingAverage = ((singles + (2 * doubles) + (3 * triples) + (4 * homeRuns)) / atBats);
        }
        else
        {
        calc.totalBases = (singles +(5 * homeRuns));
        calc.battingAverage = (singles + doubles + triples + homeRuns) / atBats;
        calc.homeRunRatio = homeRuns / atBats;
        calc.sluggingAverage = ((singles + (5 * homeRuns)) / atBats);
        }
    }
        return (calc);
    
    }
    
    int main()
    {
        double s = 216;
        double d = 37;
        double t = 6;
        double hr = 21;
        double ab = 683;
    
        struct stats data, result;
    
        result = myBaseBallStats(s, d, t, hr, ab);
    
        printf("Total Bases: %5.0f Batting Average: %1.3f Home Run Ratio: %2.2f Slugging Average: %.3f", result.battingAverage, result.battingAverage, result.homeRunRatio, result.sluggingAverage);
    
        getchar();
        return 0;
    }