洗牌,发牌程序编译没错,为什么结果出不来?
写了个洗牌和发牌的程序,程序编译正确,但运行后却没有任何结果,希望大家给看看问题出现在哪里?头文件:DeckOfCards.h
class DeckOfCards
{
public:
DeckOfCards();
void shuffle();
void deal();
private:
int deck[ 4][ 1 ];
};
函数声明 DeckOfCards1.cpp
#include <iostream>
using std::cout;
using std::left;
using std::right;
#include <iomanip>
using std::setw;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
#include "DeckOfCards.h"
DeckOfCards::DeckOfCards()
{
for ( int row = 0; row <= 3; row++ )
{
for ( int column = 0; column <= 12; column++ )
{
deck[ row ][ column ] = 0;
}
}
srand( time( 0 ) );
}
void DeckOfCards::shuffle()
{
int row;
int column;
for ( int card = 1; card <= 52; card++ )
{
do
{
row = rand() % 4;
column = rand() % 13;
} while( deck[ row ][ column ] != 0 );
deck[ row ][ column ] = card;
}
}
void DeckOfCards::deal()
{
static const char *suit[ 4 ] =
{ "Hearts", "Diamonds", "Clubs", "Spades" };
static const char *face[ 13 ] =
{ "Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack", "Queen", "King" };
for ( int card = 1; card <= 52; card++ )
{
for (int row = 0; row <= 3; row++ )
{
for ( int column = 0; column <= 12; column++ )
{
if ( deck[ row ][ column ] == card )
{
cout << setw( 5 ) << right << face[ column ]
<< " of " << setw( 8 ) << left << suit[ row ]
<< ( card % 2 == 0 ? '\n' : '\t' );
}
}
}
}
}
主函数 DeckOfCards.h
#include "DeckOfCards.h"
int main()
{
DeckOfCards deckOfCards;
deckOfCards.shuffle();
deckOfCards.deal();
return 0;
}