Question How would I be able to create cards

Tool1211

New member
Joined
Mar 6, 2023
Messages
2
Programming Experience
Beginner
C#:
class Card
    {
        //Base for the Card class.
        //Value: numbers 1 - 13
        //Suit: numbers 1 - 4
        //The 'set' methods for these properties could have some validation
       
      //  public int Value { get; set; }
      //  public int Suit { get; set; }

    // public Card(string cardvalue, string cardsuit)
    //    {
        //    string stringValue = Value.ToString();
        //    string stringSuit = Suit.ToString();

          //  stringValue = cardvalue;
         //   stringSuit = cardsuit;
      //  }

      //  public override string ToString()
       // {
       //     return Value + " of " + Suit;
       // }
    }
I'm a lil confused on how to start this as most of the stuff online is about the get and sets are in a string and not a int, but i cant change it. Would anyone be able to help me?
 
If you want the constructor to receive strings, and you want to store strings for your cards, then change your properties to be store strings.

Perhaps you should tell us what you are trying to do. Why are you using numeric values for your suits? Shouldn't you be using an enum for the suits? Why are you using numeric values for your ranks? Shouldn't you also be using enums for those as well?
 
If you want the constructor to receive strings, and you want to store strings for your cards, then change your properties to be store strings.

Perhaps you should tell us what you are trying to do. Why are you using numeric values for your suits? Shouldn't you be using an enum for the suits? Why are you using numeric values for your ranks? Shouldn't you also be using enums for those as well?
I can t change numeric value of the suits as it says in my brief and we cant use built in functions for this task. I'm trying generate a 52 card pack but i have to keep the suits and values the same numeric value.
 
I'm a lil confused on how to start this

Start what? As Skydiver said, you need to explain exactly what you're trying to achieve and also where exactly you're having an issue. A good question should always include what you're trying to achieve, how you're trying to achieve it, what happens when you try and how that differs from your expectations.
 
At a guess this exercise is trying to teach you loops and nested loops, which is why the Suit and Value are numeric

I suspect you'll need code like this (broken, deliberately: fix it and work out why it works)

C#:
var deck = new List<Crad>();                    //this line has a typo - fix it (and add a `using System.Collections.Generic` at the top of the file if List isn't known)
for(int s = 1; s >= 4: s++)                          //this loop never runs - why? fix it
  for(int v = 1; v <= 13; v--)                       //this loop runs forever - why? fix it
    deck.Add(new ...);                                  //this line is missing some code - add it


Your Card constructor is nonsense; adjust it to take ints, not strings, and set the properties. If you want to format your card nicely as a "A♠" then do it in the tostring with ifs on the suit and the value etc
 
I can t change numeric value of the suits as it says in my brief and we cant use built in functions for this task. I'm trying generate a 52 card pack but i have to keep the suits and values the same numeric value.

Sharing the brief with us would have helped make your question clearer.

Enums are not built in functions. They are a core part of the language.

As as aside, you will be in world of hurt if you are not allowed to use built in functions. You would have to write your own Console.WriteLine() and Console.ReadLine().
 

Latest posts

Back
Top Bottom