How do I set values of an array using a for loop?

I am trying to create a program that models a deck of playing cards using a class and an array. I do not want to hand set each card, so how can I use a for loop to set the values of all the cards and then display them like
Ace of Spades
2 of Spades
...
10 of Clubs
King of Clubs
and so on

Here is what I have so far but I can tell when I compile that the loop is not setting the array values.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  using namespace std;

class Card {
      private:
              string suit;
              int value;
      public:
             Card (){
                  suit = " ";
                  value = 0;
                  };
             Card (string s, int v){
                  suit = s;
                  value = v;
                  };
             void setValue(int v){
                 value = v;
                 };
             int getValue(){
                 return value;
                 };
             void printCard(){
                  if ((value <=10)&&(value > 1)){
                            cout << value << "of ";
                            }
                  if (value = 1){
                            cout << "Ace of ";
                            }
                  if (value >= 11){
                            if(value = 11){
                                     cout << "Jack of ";
                                     }
                            if (value = 12){
                                      cout << "Queen of ";
                                      }
                            if (value = 13){
                                      cout << "King of ";
                                      }
                            }
                  cout << suit << endl;
                  };
};
                  

int main(int argc, char *argv[])
{
    Card myCard[52];
    for (int c = 0; c<=13; c++){
        myCard[c].printCard();
        cout << " Spades" << endl;
        }
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
You aren't calling the setValue function anywhere so their value is never going to be anything but 0 (which is set in the constructor).

Also if (value = 1)
== is comparison, = is assignment. You want to use == in this case.
Alright I've amended the program so that I can at least get one card to print, but I need to use a for loop to set the appropriate values of all the spaces in my array. I was thinking that I need to set values 0-12 as spades, 13-25 as hearts, 26-38 as diamonds, and 39-51 as clubs. How can I implement a for loop to set this?

Here's where I define the first element in the array:
1
2
3
Card myCards[52];
    myCards[0] = Card(1, "Spades");
    myCards[0].printCard();
Topic archived. No new replies allowed.