Tuesday, March 31, 2015

Calculate the series average for a player

Script

#include <stdio.h>

main()
{
        char player[20];
        float firstODI, secondODI, thirdODI, fourthODI, fifthODI, sixthODI, seventhODI;
        float average;

        printf("\n");
        printf("Please enter the name of the player:     ");
        scanf("%s", &player);

        printf("\n");
        printf("Please enter his score in the first ODI:   ");
        scanf("%f", &firstODI);

        printf("\n");
        printf("Please enter his score in the second ODI:  ");
        scanf("%f", &secondODI);

        printf("\n");
        printf("Please enter his score in the third ODI:   ");
        scanf("%f", &thirdODI);

        printf("\n");
        printf("Please enter his score in the fourth ODI:  ");
        scanf("%f", &fourthODI);

        printf("\n");
        printf("Please enter his score in the fifth ODI:   ");
        scanf("%f", &fifthODI);

        printf("\n");
        printf("Please enter his score in the sixth ODI:   ");
        scanf("%f", &sixthODI);

        printf("\n");
        printf("Please enter his score in the seventh ODI: ");
        scanf("%f", &seventhODI);

        printf("\n");
        average = (firstODI + secondODI + thirdODI + fourthODI + fifthODI + sixthODI + seventhODI)/7;

        printf("\nPlayer:                                  %s", player);
        printf("\nFirst ODI:                                 %0.0f", firstODI);
        printf("\nSecond ODI:                                %0.0f", secondODI);
        printf("\nThird ODI:                                 %0.0f", thirdODI);
        printf("\nFourth ODI:                                %0.0f", fourthODI);
        printf("\nFifth ODI:                                 %0.0f", fifthODI);
        printf("\nSixth ODI:                                 %0.0f", sixthODI);
        printf("\nSeventh ODI:                               %0.0f", seventhODI);
        printf("\n                                        ==========");
        printf("\nAverage for the series for %s:     %.2f", player, average);
        printf("\n                                        ==========");
        printf("\n\n\n");
}


Execution


Please enter the name of the player:     Tendulkar

Please enter his score in the first ODI:   59

Please enter his score in the second ODI:  45

Please enter his score in the third ODI:   11

Please enter his score in the fourth ODI:  29

Please enter his score in the fifth ODI:   147

Please enter his score in the sixth ODI:   54

Please enter his score in the seventh ODI: 59


Player:                                  Tendulkar
First ODI:                                 59
Second ODI:                                45
Third ODI:                                 11
Fourth ODI:                                29
Fifth ODI:                                 147
Sixth ODI:                                 54
Seventh ODI:                               59
                                        ==========
Average for the series for Tendulkar:     57.71
                                        ==========



No comments:

Post a Comment