I'm creating a program for deck of cards. It works fine but only error I get is that it shows duplicate cards - no card should be displayed twice. Tried all you guys suggested. basically this is brand new for me and all the advance methodology you are talking about haven't been taught yet. Also searched and looked for all the solutions available for deck of cards, doesn't help though.
namespace DeckofCards
{
class Program
{
static void Main(string[] args)
{
Console.Title = "DECKOFCARDS";
String UI = "";
while (UI.ToUpper() != "Q")
{
Console.Clear();
Console.WriteLine("Please Press Q to Quit");
UI = Console.ReadLine();
if (UI.ToUpper() == "Q")
{
break;
}
List<String> Faces = new List<string>();
List<String> Suits = new List<string>();
Faces.Add("Ace");
Faces.Add("1");
Faces.Add("2");
Faces.Add("3");
Faces.Add("4");
Faces.Add("5");
Faces.Add("6");
Faces.Add("7");
Faces.Add("8");
Faces.Add("9");
Faces.Add("10");
Faces.Add("Jack");
Faces.Add("Queen");
Faces.Add("King");
Suits.Add("Hearts");
Suits.Add("Spades");
Suits.Add("Clubs");
Suits.Add("Diamonds");
Console.WriteLine("How many cards do you want.?");
string Input = Console.ReadLine();
int NumberOfCards = 0;
Random RanFaces = new Random();
Random RanSuits = new Random();
{
if (int.TryParse(Input, out (NumberOfCards))) // to handle incorrect (alphabetic) inputs
if (NumberOfCards <= 52 && NumberOfCards > 0)
{
for (int Output = 0; Output < NumberOfCards; ++Output)
{
int RandomFaces = RanFaces.Next(0, 12);
int RandomSuits = RanSuits.Next(0, 3);
Console.WriteLine("Your Cards are {0} of {1}", Faces[RandomFaces], Suits[RandomSuits]);
if ((Output + 1) % 4 == 0)
Console.WriteLine();
}
}
else
{
Console.WriteLine("This is not a Valid number of cards.");
}
else
{
Console.WriteLine("This is not a Valid number of cards.");
}
Console.ReadLine();
}
}
}
}
}