GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Oct-2003, 18:55
ryz ryz is offline
Awaiting Email Confirmation
 
Join Date: Oct 2003
Posts: 1
ryz is an unknown quantity at this point

can't solve the sum


hello anybody...this one of my runable program...but i still got a problem how to calculate total point for each player...all the way that i use causes a lot of syntax error and i don't know why...this is the question...if i got the way to solve how to find the total point for each player...then i can complete my program...

question :CARD GAME;

Create a class card with relevant information (each card is having a color and value) and functions.
Create a pack of standard playing card using class card. Write a module to shuffle the cards at random and distribute to 3 players equally at random.
Display the set of card with each player.
The point for the color of the card given below:
Spades: 15
Diamonds: 10
Clubs: 5
Hearts: 0

The points for the value of the card is equal to the number on the card it self if it is 2 to 10 and jack = 11, queen = 12, king = 13, ace = 14
The program has to find which player has the highest total point for the cards and will be the winner.

i hope someone can help me to solve it or modify my program.
CPP / C++ / C Code:
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<ctime>

using namespace std;

enum Suit{hearts, clubs, diamonds, spades};
// from 2 to 10 are integers without names
const int jack  = 11;
const int queen = 12;
const int king  = 13;
const int ace   = 14;

//////////////////////////////////////////////////////////////////////////////////

class card
    {
    private:
        int number;                             //2 to 10, jack, queen, king, ace
        Suit suit;                              //hearts, diamonds, clubs, spades
    public:
        card()
        { }
        void set(int n, Suit s)                 // set card
            { suit = s; number = n;}
        int getsuit(){return suit;};
        int getnumber(){return number;};
        void display();                         // display card
        };

//////////////////////////////////////////////////////////////////////////////////

void card::display()                            //display card
    {
    if(number >=2 && number <= 10)
       cout<< number;
    else
       switch(number)
          {
          case jack:    cout<<"J";
          break;
          case queen:   cout<<"Q";
          break;
          case king:    cout<<"K";
          break;
          case ace:     cout<<"A";
          break;
          } 
        switch(suit)
        {
        case hearts:    cout<<static_cast<char>(3);
        break;
        case diamonds:  cout<<static_cast<char>(4);
        break;
        case clubs:     cout<<static_cast<char>(5);
        break;
        case spades:    cout<<static_cast<char>(6);
        break;
        }
       }
////////////////////////////////////////////////////////////////////////////////

int main()
    {
    card deck[52];
    int j,v=0,w=13,x=26,y=39;
    
    cout<<"\n\t\tWelcome To Royal Card Games"<<endl;
    
    for (j=0; j <52; j++)                      //make an ordered deck
        {
        int num = (j % 13) + 2;               //cycles through 2 to 14, 4 times
        Suit su  = Suit(j /13);                //cycles through 0 to 3, 13 times
        deck[j].set(num, su);                  //set card
        }
    cout<<"\nOrdered Deck : \n\n";
    for(j=0; j<52; j++)                        //display ordered deck
        {
        deck[j].display();
        cout<<setw(3)<<" ";
        if( !( (j+1) % 13) )                   //newline every 13 cards
            cout<< endl;
        }
    
    srand(time(NULL));                         //seed random numbers with time
    for(j=0; j <52; j++)                       //for each card int hte deck
        {
        int k = rand() % 52;                   //pick another card at random
        card temp = deck[j];                   //and swap them
        deck[j] = deck[k];
        deck[k] = temp;
        }
    cout<<"\n_________________________________________________________________";
    cout<<"\n\nShuffled Deck : \n\n";
    for(j=0; j<52; j++)                        //display shuffled deck
        {
        deck[j].display();
        cout<<setw(3)<<", ";
        if( !( (j+1) % 13) )                   //newline every 13 cards
                cout<<endl;
        }
        cout<<"\n_________________________________________________________________";
        cout<<"\n\n\n";
        system("pause");
        system("cls");
        cout<<"\n\nCard has been distributed to four players:"<<endl;
        cout<<"\n\n\n"<<endl;
        cout<<"Player 1\t"
            <<"Player 2\t"
            <<"Player 3\t"
            <<"Player 4\t\n"<<endl;
        
        while(y<52)
        {deck[v].display();             //display player 1 card
        v++;
        cout<<"\t\t";
         deck[w].display();            //display player 2 card
        w++;
        cout<<"\t\t";
         deck[x].display();            //display player 3 card
        x++;
        cout<<"\t\t";
         deck[y].display();           //display player 4 card
        y++;
        cout<<"\t\t";
        cout<<"\n";}
        cout<<"\n\n";
        
     
        
        
        system("pause");
        return 0;
}
 
 

Recent GIDBlogRunning Linux Programs at Boot Time by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
.htaccess on Windows2k, and the trailing slash Pedster2k Apache Web Server Forum 6 24-Jan-2004 17:32

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:41.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.