I just writing the simple twenty one card game...now evth work and fine.
And I put cards from 2 to A with concerning value.But when the debug step coming '0'comes to input with value '10'(K is worth 10 etc). It make me so confused.
here is my code:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

struct
{
   char face;
    unsigned int value;
} 
card[13] = 
{	{'2', 2},{'2', 3},{'2', 4},
    {'5', 5},{'6', 6},{'7', 7},
    {'8', 8},{'9', 9},{'10', 10},
    {'J', 10},{'Q', 10},{'K', 10},
    {'A', 1}
};

int main()
{

	cout<<"simple twenty one card"<<endl;
	cout<<"------------------------"<<endl;
	int compcard=3,compscore=0,urscore=0,draw=0,urcard=0;
	char cond;
	const int high=21;
	//int ur;
	do
	{
		int comptotal=0,urtotal=0;
		//srand(time(NULL));
		srand((unsigned)time(0));
		cout<<"how many cards u want?(up to 5 cards)"<<endl;
		cin>>urcard;
	if (urcard>5)
	cout<<"You could not get more than five cards!"<<endl;
	else
	{
		cout<<endl<<"Ur cards..."<<endl;
		for (int ucard=0;ucard<urcard;ucard++)
		{
			int x = rand() % 13;
			printf(" |%c| ", card[x].face);
			
			urtotal+=card[x].value;
			if(urtotal>42)
			{
				urtotal=urtotal-30;
			}
			else if(urtotal>31&&urtotal<42)
			{
				urtotal=urtotal-20;
			}
			else if(urtotal>21&&urtotal<32)
			{
				urtotal=urtotal-10;
			}
			
		}

		cout<<endl;
		cout<<"My cards..."<<endl;
		for (int Ccard=0;Ccard<compcard;Ccard++)
		{
			int x = rand() % 13;
			printf(" |%c| ", card[x].face);
			comptotal+=card[x].value;
			
			if(comptotal>42)
			{
				comptotal=comptotal-30;
			}
			else if(comptotal>31&&comptotal<42)
			{
				comptotal=comptotal-20;
			}
			else if(comptotal>21&&comptotal<32)
			{
				comptotal=comptotal-10;
			}
			
		}
		cout<<endl;
		cout<<"I have "<<comptotal<<" and you have "<<urtotal<<" so ";

		if(comptotal<=high&& urtotal<comptotal)
		{
			cout <<"I win "<<endl;
			compscore++;
		}
		else if(comptotal<=high&& urtotal>high)
		{
			cout <<"I win "<<endl;
			compscore++;
		}
		else if (urtotal<=high&& urtotal>comptotal)
		{cout<<" you win"<<endl;
		urscore++;
		}
		else if (urtotal<=high&& comptotal>high)
		{cout<<" you win"<<endl;
		urscore++;
		}
		else //(comptotal==urtotal)
		{cout<<"no win"<<endl;
		draw++;
		}
	}
		cout<<"wana play again(n/y?)"<<endl;
		cin>>cond;
	}while(cond=='y');
		cout<<"I win   : "<<compscore<<endl;
		cout<<"you win : "<<urscore<<endl;
		cout<<"we draw : "<<draw<<endl;
		cout<<endl;
		//cin>>ur;

		
}

example of output is like " |4||J||0||k||8|".
I dont want to include "0" . How can I do? Pls tell me.
Thanks in advance!:)

Recommended Answers

All 5 Replies

Member Avatar for iamthwee

Hint
Ask yourself why is it displaying, then how you might ignore it?

Hint
Ask yourself why is it displaying, then how you might ignore it?

I dont know .. I try already..:mad:

{'J', 10},{'Q', 10},{'K', 10},
    {'A', 1}

The above are all wrong. the values of J, Q, K and A are incorrect, should be 11, 12 , 13 and 14 respectively.

It's implementation defined what happens when you use an unrecognised character literal. You use '10', and that has too many expected characters, and C++ is seeing it as '0'.

#include <cstdio>

int main()
{
  using namespace std;

  char x = '10';

  printf( "%d\t%c\n", x, x );
}

Thanks a lot u guys...
you guys r so helpful..

but now i ran again after a bit change .. it still happen like that..
i change J to 11 and K to sth . not same value..
:sad:

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.