P
Pieter-Jan Ahenkona
Guest
Hey guys
I've been stuck at this exercise of making an array of cards and then picking a random card out of the first array and then storing it in the second one. My choice of loop is a do while where I increment I (the position of the card in the second array). Although it seems that i does not increment as i thought it would. Could somebody please tell me where i went wrong with this exercise it should be a really easy solve. Thanks in advance.
static void Main(string[] args)
{
string[] myCards = new string [52] {"H1","H2","H3","H4","H5","H6","H7","H8","H9","HT","HJ","HQ","HK",
"D1", "D2","D3","D4","D5","D6","D7","D8","D9","DT","DJ","DQ","DK",
"C1", "C2","C3","C4","C5","C6","C7","C8","C9","CT","CJ","CQ","CK",
"S1", "S2","S3","S4","S5","S6","S7","S8","S9","ST","SJ","SQ","SK"};
int i=0;
bool stopPlaying= true;
string[] arrDeckOfCardsPulled;
arrDeckOfCardsPulled = new string[52];
do
{
Console.Write("Choose one of the following options:");
Console.WriteLine(" 'A' : To pick a card.");
Console.WriteLine("\t\t\t\t\t\t 'B' : To fold the deck and END the game.");
string plaOrNot = Console.ReadLine();
Random random = new Random();
int randomCard = random.Next(0,52);
string valueOfMycard = myCards[randomCard];
if (randomCard != Array.IndexOf(arrDeckOfCardsPulled, randomCard)) {
switch (plaOrNot)
{
case "A":
{
arrDeckOfCardsPulled = valueOfMycard;
Console.WriteLine();
Console.WriteLine("This is the card you picked: " + myCards[randomCard]);
Console.WriteLine();
Console.WriteLine("This is the position of your card in the first array: " + Array.IndexOf(myCards, valueOfMycard));
Console.WriteLine();
Console.WriteLine("This is the position of your card in the second array: " + Array.IndexOf(arrDeckOfCardsPulled, valueOfMycard));
i++;
}
break;
case "B":
Console.Write("These are the cards that you pulled.");
foreach (string card in arrDeckOfCardsPulled)
{
Console.Write(card+" ");
}
Console.WriteLine();
Console.Write("I am folding the deck.");
Console.WriteLine();
Console.Write("\n\t\t\t\t\t\t THE END");
Console.WriteLine("\n");
Console.ReadKey();
stopPlaying = false;
break;
default:
break;
}
Console.WriteLine("\n");
}
} while (stopPlaying||(i)<52);
}
Continue reading...
I've been stuck at this exercise of making an array of cards and then picking a random card out of the first array and then storing it in the second one. My choice of loop is a do while where I increment I (the position of the card in the second array). Although it seems that i does not increment as i thought it would. Could somebody please tell me where i went wrong with this exercise it should be a really easy solve. Thanks in advance.
static void Main(string[] args)
{
string[] myCards = new string [52] {"H1","H2","H3","H4","H5","H6","H7","H8","H9","HT","HJ","HQ","HK",
"D1", "D2","D3","D4","D5","D6","D7","D8","D9","DT","DJ","DQ","DK",
"C1", "C2","C3","C4","C5","C6","C7","C8","C9","CT","CJ","CQ","CK",
"S1", "S2","S3","S4","S5","S6","S7","S8","S9","ST","SJ","SQ","SK"};
int i=0;
bool stopPlaying= true;
string[] arrDeckOfCardsPulled;
arrDeckOfCardsPulled = new string[52];
do
{
Console.Write("Choose one of the following options:");
Console.WriteLine(" 'A' : To pick a card.");
Console.WriteLine("\t\t\t\t\t\t 'B' : To fold the deck and END the game.");
string plaOrNot = Console.ReadLine();
Random random = new Random();
int randomCard = random.Next(0,52);
string valueOfMycard = myCards[randomCard];
if (randomCard != Array.IndexOf(arrDeckOfCardsPulled, randomCard)) {
switch (plaOrNot)
{
case "A":
{
arrDeckOfCardsPulled = valueOfMycard;
Console.WriteLine();
Console.WriteLine("This is the card you picked: " + myCards[randomCard]);
Console.WriteLine();
Console.WriteLine("This is the position of your card in the first array: " + Array.IndexOf(myCards, valueOfMycard));
Console.WriteLine();
Console.WriteLine("This is the position of your card in the second array: " + Array.IndexOf(arrDeckOfCardsPulled, valueOfMycard));
i++;
}
break;
case "B":
Console.Write("These are the cards that you pulled.");
foreach (string card in arrDeckOfCardsPulled)
{
Console.Write(card+" ");
}
Console.WriteLine();
Console.Write("I am folding the deck.");
Console.WriteLine();
Console.Write("\n\t\t\t\t\t\t THE END");
Console.WriteLine("\n");
Console.ReadKey();
stopPlaying = false;
break;
default:
break;
}
Console.WriteLine("\n");
}
} while (stopPlaying||(i)<52);
}
Continue reading...