# c++ card game,, just need a start up, and a little hint

Page 1 of 1

## 5 Replies - 4733 Views - Last Post: 03 May 2010 - 11:46 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=171784&amp;s=97da71d29e1fabb83a79d135e95144d9&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 0
• Posts: 4
• Joined: 03-May 10

# c++ card game,, just need a start up, and a little hint

Posted 03 May 2010 - 10:39 AM

The program imitates a gambling card game. The program shows you three cards, then the program interchange them, and if you can guess correctly where a particular card is, you win.

Here is some sample interaction with the program:
Card 1 is the 7 of clubs
Card 2 is the jack of hearts
Card 3 is the ace of spades
I’m swapping card 1 and card 3
I’m swapping card 2 and card 3
I’m swapping card 1 and card 2
Now, where (1, 2, or 3) is the ace of spades?
If the user insert 3
The program will print” sorry, you lose.”

Solution hints:
Implement the previous program using structure, this structure represent the data of Card (number and suit), so the structure uses separate members to hold of the number of the card and suit. The number runs from 2 to 14, where 11, 12, 13 and 14 represent the jack, queen, king, and ace, respectively. The suit runs from 0 to 3, where these four numbers represent clubs, diamonds, hearts, and spades.

sorry for being anoyying, but it is very important

Is This A Good Question/Topic? 0

## Replies To: c++ card game,, just need a start up, and a little hint

• Saucy!

Reputation: 6219
• Posts: 23,965
• Joined: 23-August 08

## Re: c++ card game,, just need a start up, and a little hint

Posted 03 May 2010 - 10:48 AM

Don't double post. I deleted the first topic you created.

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Thank you for helping us helping you.

Reputation: 0
• Posts: 4
• Joined: 03-May 10

## Re: c++ card game,, just need a start up, and a little hint

Posted 03 May 2010 - 11:10 AM

```#include <iostream>
class Card
{
int number;
string suit;

public:
Card () {};
~Card () {};
Card(int n,string s) , number(n), suit(s) {};
Card& operator= (const Card d)
{
number=d.number;
suit=d.suit;
}
friend bool operator== (const Card c,const Card d)
{
return (c.number==d.number) && (c.suit==d.suit);
}
friend ostream& operator << (ostream& o,Card d) {return o<<d.number << endl << d.suit;}
};

void SwapCards(Card&,Card&);

void main ()
{
Card two(6,"clubs");
SwapCards(one,two);
}

void SwapCards(Card& a,Card& B)/>
{
Card chair;
chair=a;
a=b;
b=chair;
}
```

that what i have done, plz any help

### #4 snoopy11

• Engineering ● Software

Reputation: 1022
• Posts: 3,095
• Joined: 20-March 10

## Re: c++ card game,, just need a start up, and a little hint

Posted 03 May 2010 - 11:17 AM

Dude there is no way that will work
small help
you need to #include <string>

but then there is still no way that it'll work but it helps a little.

I cant write the program for you or I will get in trouble.

but what you need to do is
set up something like this example

```#include <string>
#include <iostream>
using namespace std;

class Dog
{

//private variables
int age,weight;
string color;

//public variables
public:

void bark(){ cout<<"WOOF!"<< endl;}
void setAge(int yrs) {age =yrs;}
void setWeight(int lbs) {weight = lbs;}
void setColor(string clr) {color =clr;}
int getAge() {return age;}
int getWeight() {return weight;}
string getColor() {return color;}

};

int main()
{
//main program staements
Dog fido;
fido.setAge(3);
fido.setWeight(15);
fido.setColor("brown");

cout << "Fido is a "<<fido.getColor()<<" dog"<<endl;

cout << "Fido is "<<fido.getAge()<<" years old"<<endl;

cout << "Fido weighs "<<fido.getWeight()<<" pounds"<<endl;

// regular output method
fido.bark();

return 0;
}

```

This post has been edited by snoopy11: 03 May 2010 - 11:43 AM

### #5 joesyuh

Reputation: 36
• Posts: 175
• Joined: 30-September 08

## Re: c++ card game,, just need a start up, and a little hint

Posted 03 May 2010 - 11:24 AM

Could you please use the code tags when you put code in to the forums. It makes it easier to read these threads and your code.

### #6 Oler1s

• D.I.C Lover

Reputation: 1396
• Posts: 3,884
• Joined: 04-June 09

## Re: c++ card game,, just need a start up, and a little hint

Posted 03 May 2010 - 11:46 AM

This isn't a free homework forum. You seem to think that after dumping token code here, we'll do the rest of the program for you...

When you ask for help here, you need to have a clear question in mind. You should be able to explain how you have attempted to answer your question, and what precisely prevents you from answering it.

If you just dump an assignment along with token code, we aren't going to take it up and finish it for you...