locked
Counting An Array for Numbers RRS feed

  • Question

  • Hi

    I was trying to make a program to calculate a poker hand in the form of card values ranging from 1-13. I was trying to see how many 5's or 8's etc were typed in by the user but I cant seem to get a counter up and working, I have notes so ill show my notes and hopefully someone can tell me how to declare or use what im attempting to use.

    hand = the array with which the users cards are stored.

    count = the array which counts and stores the amount of each number in the hand array.

    Code Notes:

    declaration.

    int[] count

    int[] hand

    hand = new int[5]

    count = new int[14]

    Loop for counting numbers.

    for (i = 0; i < 5; i++)

    count(hand[ i ]) = count(hand[ i ]) + 1;

    for some reason i get a error sayting that count is used as a method, im not sure whether to do this kind of code i need to delcare it differently or need to change the actual working of it.

    Thanks

    Sammaye

    Sunday, January 28, 2007 3:10 PM

Answers

  • Use square brackets when indexing the count array:
      count [hand[ i ]] += 1;
    Sunday, January 28, 2007 6:11 PM
    Moderator

All replies

  • Use square brackets when indexing the count array:
      count [hand[ i ]] += 1;
    Sunday, January 28, 2007 6:11 PM
    Moderator
  • Woo, works pefectly :). Thanks for the help! And just to think it was something that small.
    Sunday, January 28, 2007 8:11 PM