Click here to Skip to main content
16,005,491 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Sending Email with C++. Possible? Pin
ThatsAlok1-Jan-07 23:25
ThatsAlok1-Jan-07 23:25 
AnswerRe: Sending Email with C++. Possible? Pin
Hamid_RT3-Jan-07 6:57
Hamid_RT3-Jan-07 6:57 
Questionwav to mp3 coverter using vc++ help needed Pin
alphaq1-Jan-07 18:14
alphaq1-Jan-07 18:14 
AnswerRe: wav to mp3 coverter using vc++ help needed Pin
Trollslayer2-Jan-07 1:21
mentorTrollslayer2-Jan-07 1:21 
AnswerRe: wav to mp3 coverter using vc++ help needed Pin
Hamid_RT3-Jan-07 6:57
Hamid_RT3-Jan-07 6:57 
QuestionDSN less connection Pin
apoorva_raje1-Jan-07 18:12
apoorva_raje1-Jan-07 18:12 
AnswerRe: DSN less connection Pin
bob169721-Jan-07 19:13
bob169721-Jan-07 19:13 
QuestionNot for repeat displayed cards again! Pin
davvid1-Jan-07 17:50
davvid1-Jan-07 17:50 
Hi all,
I am just new to progamming .I am writng small twenty card game.What I want I dont repeat the cards again to next player after first user received.And in real I wana do game with more than two player.But in my code have some problem with print out total score that who win or lose (only two player is ok).I can get total score by comparing two player. But I want to compare with more than two players.How can I do with my code.
here is my simple code.. Thanks in advance.

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
void display();
void intro();
int your_total(int urcard);
int comp_total(int compcard);
struct{
int face;
unsigned int value;
} 
card[13] = 
{	{'2', 2},{'2', 3},{'2', 4},
    {'5', 5},{'6', 6},{'7', 7},
    {'8', 8},{'9', 9},{'X', 10},
    {'J', 13},{'Q', 12},{'K', 11},
    {'A', 1}
};
char suit[4]={'D','C','H','S'};

int main()
{
intro();
display();
return 0;
}
void intro()
{
	cout<<"simple twenty one card"<<endl;
	cout<<"------------------------"<<endl;
	cout<<"Total number gotta cut out upon number21!"<<endl;
	cout<<"But u can have only 5 cards in maximum"<<endl;
	cout<<"<TenX=10,King=11,Queen=12,Jack=13,Ace=1>"<<endl<<endl;
}
int your_total(int urcard)
{
	int urtotal=0;
	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<<"     Ur card"<<endl;
				for (int ucard=0;ucard<urcard;ucard++)
				{
					int x = rand() % 13;
					char d;
					d=rand()%4;
					cout<<" |"<<suit[d];
					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;
				}
		}
		
		return urtotal;
		
}
int comp_total(int compcard)
{
			srand((unsigned)time(0));
			
			cout<<endl<<"How many cards you want computer?"<<endl;
			int lowest=2, highest=5; 
			int range=(highest-lowest)+1;
			int total_num=0;
					for(int index=0; index<1; index++){ 
					compcard= lowest+int(range*rand()/(RAND_MAX + 1.0)); 
					cout <<compcard<<endl;
					}
			cout<<"     My cards"<<endl;
			  for (int Ccard=0;Ccard<compcard;Ccard++)
			  {
				 	int x = rand() % 13;
				char d;
				d=rand()%4;
				cout<<" |"<<suit[d];
				printf("%c| ", card[x].face);
				total_num+=card[x].value;
				if(total_num>42)
				total_num=total_num-30;
				else if(total_num>31&&total_num<42)
				total_num=total_num-20;
				else if(total_num>21&&total_num<32)
				total_num=total_num-10;
				
		     }
			return total_num;
		  

}
void display()
{
	int comptotal, urtotal,person=0,computer=0, compscore=0,urscore=0,draw=0;
	const int high=21;
	char cond;
	int ur;
	do{
	
		//srand(time(NULL));
		srand((unsigned)time(0));
		urtotal=your_total(person);
		comptotal=comp_total(computer);
		
		cout<<endl<<"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<<endl<<"Wana play again(n/y?)"<<endl;
		cin>>cond;
	}while(cond=='y');
	cout<<"I win: "<<compscore<<endl<<"U win: "<<urscore<<endl<<"Draw : "<<draw<<endl;
	cin>>ur;

}

QuestionXAML Pin
math071-Jan-07 17:34
math071-Jan-07 17:34 
AnswerRe: XAML Pin
Christian Graus1-Jan-07 18:07
protectorChristian Graus1-Jan-07 18:07 
Questionremove program from start up Pin
Alinuxcs1-Jan-07 16:25
Alinuxcs1-Jan-07 16:25 
AnswerRe: remove program from start up Pin
ThatsAlok1-Jan-07 23:28
ThatsAlok1-Jan-07 23:28 
QuestionRe: remove program from start up Pin
Alinuxcs2-Jan-07 3:27
Alinuxcs2-Jan-07 3:27 
QuestionExposing a PERF_AVERAGE_TIMER performance counter [modified] Pin
Martin.Lanza1-Jan-07 12:30
Martin.Lanza1-Jan-07 12:30 
QuestionHow to prevent Screen Saver from turning on Pin
spiritofklanawa1-Jan-07 7:10
spiritofklanawa1-Jan-07 7:10 
AnswerRe: How to prevent Screen Saver from turning on Pin
PJ Arends1-Jan-07 7:27
professionalPJ Arends1-Jan-07 7:27 
AnswerRe: How to prevent Screen Saver from turning on Pin
Michael Dunn1-Jan-07 9:43
sitebuilderMichael Dunn1-Jan-07 9:43 
GeneralRe: How to prevent Screen Saver from turning on Pin
PJ Arends1-Jan-07 9:57
professionalPJ Arends1-Jan-07 9:57 
GeneralRe: How to prevent Screen Saver from turning on Pin
Michael Dunn1-Jan-07 10:03
sitebuilderMichael Dunn1-Jan-07 10:03 
Questionfatal error LNK1120: 1 unresolved externals in visual c++ 2005 Pin
x-coder20071-Jan-07 6:19
x-coder20071-Jan-07 6:19 
AnswerRe: fatal error LNK1120: 1 unresolved externals in visual c++ 2005 Pin
PJ Arends1-Jan-07 7:01
professionalPJ Arends1-Jan-07 7:01 
AnswerRe: fatal error LNK1120: 1 unresolved externals in visual c++ 2005 Pin
toxcct1-Jan-07 8:04
toxcct1-Jan-07 8:04 
AnswerRe: fatal error LNK1120: 1 unresolved externals in visual c++ 2005 Pin
Shouvik Das1-Jan-07 19:28
Shouvik Das1-Jan-07 19:28 
GeneralRe: fatal error LNK1120: 1 unresolved externals in visual c++ 2005 Pin
x-coder20072-Jan-07 7:03
x-coder20072-Jan-07 7:03 
Questionpreassure meter Pin
ahmad al-omar1-Jan-07 5:31
ahmad al-omar1-Jan-07 5:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.