Index ALL OF A SUDDEN out of bounds of Array

Ok, its me again. I am trying to mold my brain into thinking in Codese and I thought I had a decent way of creating a Deck of Cards.

Everything was working and seem to be going fine when BLAM! - I get an out of bounds of array exception.

I have two arrays (One with the Suits of the cards and one with the Numbers or Ranks of the Cards) -- then I was iterating through them and creating a new object that added the two arrays together.

**BTW - I am SURE there are a million better ways to do what I am trying but I am trying to create this with what I have right now in my brain**

Anyway, I create the object then write it to the screen and begin the next iteration. It was filling up nicely -- THREE SUITS were completely filled up and the fourth one was filling up BUT when it gets to the 10th value of the Rank array I get an Exception - Index out of bounds of Array - error.

It doesnt make any sense to me because I have gone BEYOND the 10th value 3 times already in the other suits. --

--- CAN SOMEONE give me a clue why I am getting this? ---
============
here is the code.

namespace ConsoleApplication1
{
{
class card
{
public string suit = "Clubs";
public string rank = "One";
public string[] Suits = new string[] { "h", "d", "c", "s" };
public string[] Ranks = new string[] { "A", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };



}
}

class Program
{


static void Main(string[] args)
{

card mycard = new card();

string card = mycard.rank + " of " + mycard.suit;
string[] cards = new string[52];


int s;
int r;
int i = 0;

for (s = 0; s < 5; s++)
{
for (r = 0; r < 14; r++)
{

cards[i] = mycard.Suits[s] + " of " + mycard.Ranks[r];
Console.WriteLine(cards[i]);

i++;
}
}







}
}
}

Comments

  • OK!!! -- Moron here! -- I found the OBVIOUS ANSWER!

    Just in case someone wants some fun and couldn't figure it out, I will put it down a little below so you can think about it.


















    Here's a hint ... have you ever seen the 1 of Clubs? or 1 of anything?!?

    I had the Ranks listing an "A" and a "1" as well -- thats the same card dorkwad!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion