in the function "deal", I want to call the function "add", but it doesn't work .... any suggestions?

#include "DeckOfCards.h"

int DeckOfCards::deal()
{
  int y,z;
  int y1,y2;
  char x1,x2;
  char cards[13]={'A','2','3','4','5','6','7','8','9','0','J','Q','K'};
  char deck [260] ;

  for (int i=0; i< 260; i++)
    deck[i] = cards [i % 13];

  y = rand()%260;
  cout << "Dealer shows a: " << deck[y] << endl;

  y = rand()%260;
  x1 = deck[y];
  cout << "Your hand: " << deck[y] << " ";
  add(x1,y1);

  y = rand()%260;
  x2 = deck[y];
  cout << deck[y] << endl;
  add(x2,y2);
}

int DeckOfCards::add(char a, int b)
{
  if(a=='2')
    b+=2;
  else if(a=='3')
    b+=3;
  else if(a=='4')
    b+=4;
  else if(a=='5')
    b+=5;
  else if(a=='6')
    b+=6;
  else if(a=='7')
    b+=7;
  else if(a=='8')
    b+=8;
  else if(a=='9')
    b+=9;
  else if(a=='0')
    b+=10;
  else if(a=='J')
    b+=10;
  else if(a=='Q')
    b+=10;
  else if(a=='K')
    b+=10;
  else if(a=='A')
    b+=11;
}

Recommended Answers

All 3 Replies

"Doesn't work" is the worst possible description of a problem. Maybe you should try being more specific.

well in the function "add" I want to add "b" to the specified number, and in the function "deal" I want sign "y1" to "b" in "add", so that "y1" will also be added to the number, and the same thing goes for "y2".

but if I put in function "deal":
cout << y1 << " " << y2 << endl;

this comes out:
0 1190668742

well in the function "add" I want to add "b" to the specified number, and in the function "deal" I want sign "y1" to "b" in "add", so that "y1" will also be added to the number, and the same thing goes for "y2".

but if I put in function "deal":
cout << y1 << " " << y2 << endl;

this comes out:
0 1190668742

Since you never initialized y2, you start out with junk in it. Initialize y2 before using it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.