Posted by: Sourav | November 24, 2012

A simple card game in c++


#include <iostream>

using namespace std;

const int clubs=0;
const int diamonds=1;
const int hearts=2;
const int spades=3;
const int jack =11;
const int queen=12;
const int king=13;
const int ace=14;

struct card
{
    int number;

    int suit;

};

int main()
{
card temp,chosen,prize;

int position;

card card1={7,clubs};
cout<<“Card 1 is the 7 of clubs\n”;

card card2={jack,hearts};

cout<<“Card 2 is the jack of hearts\n”;

card card3={ace,spades};

cout<<“Card 3 is the ace of spades\n”;

prize=card3;

cout<<“I am swapping card1 and card3\n”;

temp=card3;

card3=card1;

card1=temp;

cout<<“I am swapping card2 and card3\n”;

temp=card3;

card3=card2;

card2=temp;

cout<<“I am swapping card1 and card2\n”;

temp=card2;

card2=card1;

card1=temp;

cout<<“Now where(1,2 or 3) is the ace of spades? “;

cin>>position;

switch (position)
{
    case 1:chosen=card1;break;
    case 2:chosen=card2;break;

    case 3:chosen=card3;break;

}

if((chosen.number==prize.number) && (chosen.suit=prize.suit))
cout<<“You win!!!!!!!!!!”;

else

cout<<“Sorry you lose”;

return 0;

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: