Tutorial 40 (Fantasy Hockey) - How to replace int w/ string

+1 Viraj Aditya · May 3, 2015
How can I replace the int player[5] data type to store a string of text rather than numbers?
Instead of,
= {10, 99, 23, 07, 11};

 I want my values to be string of texts, like,

= {Player 1, Player 2, Player 3, Player 4, Player 5}

How do I achieve this? Any suggestion would be helpful!



//Program to calculate batting average of Batsman.

    int main(){
        int i;
        int player[5] = {10, 99, 23, 07, 11};
        int runsScored[5] = {1009, 890, 770, 899, 1005};
        int matchesPlayed[5] = {10, 10, 8, 7, 9};
        float average[5];
        float bestAverage = 0.0;
        int bestPlayer;

        for(i=0;i bestAverage){
                bestAverage = average[i];
                bestPlayer = player[i];

        }
    }

        printf("\n\nThe best player is Player No. %d.\n", bestPlayer);

    return 0;
    }

Post a Reply

Replies

Oldest  Newest  Rating
0 Onkar Mumbrekar · May 4, 2015
char player[5][10]={"Player 1", "Player 2", "Player 3", "Player 4", "Player 5"};

this will solve your problem......
0 http://coding.developer.se/   · May 5, 2015
I don't know... My book, K&R, doesn't teach me anything so basic!
  • 1

C

107,295 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator