标识符未找到错误C ++

时间:2012-07-12 10:16:24

标签: c++ initialization

我的C ++代码出错了。我通常是一名Java开发人员,但我正在上C ++课程,使我的编程能力更加广泛。无论如何,当我尝试构建此解决方案时,我收到错误

  

1> c:\ users \ westlakes \ documents \ visual studio 2010 \ projects \ blackjack \ blackjack \ playblackjack.cpp(81):错误C3861:'initializeGame':未找到标识符
  1> c:\ users \ westlakes \ documents \ visual studio 2010 \ projects \ blackjack \ blackjack \ playblackjack.cpp(82):错误C3861:'deal':未找到标识符
  1> c:\ users \ westlakes \ documents \ visual studio 2010 \ projects \ blackjack \ blackjack \ playblackjack.cpp(83):错误C3861:'playGame':未找到标识符

任何人都可以帮助我吗?

// Programmer:  Matt Westlake

// Course:  COMP220

// Assignment:  Two-Dimensional Arrays

// Description:  The program will use a 2D array and a random-number
// generation to play Blackjack and keep track of a playing-card deck.

// Input:  User data entry and a playing-card deck represented as a two-
// dimensional array

// Output:  A screen display showing the current card hands of each player
// and the dealer, their score, win and lose status, and a final representation
// of the card deck after the game is over

#include <iostream>
#include <iomanip>
#include <windows.h>

using namespace std;

char cPlay = 'Y';       //Character variable for play game input
char tempDealerHand;
char cCardDeck[4][13];  //Character array representing the card deck
char output[5][8];
char card[1][1];
int iCard;              //Card array index
char cardName;
//0 = 2 card                                                              
//1 = 3 card
//2 = 4 card
//3 = 5 card
//4 = 6 card
//5 = 7 card                                                           
//6 = 8 card                                                        
//7 = 9 card                                     
//8 = 10 card                                                       
//9 = jack card
//10 = queen card
//11 = king card
//12 = ace card
int iNumberOfDraws = 0; //Number of rounds of card draws
int iSuit;//Suit array index
char Suit [4]; 

 //0 = diamonds
//1 = hearts
//2 = clubs
//3 = spades

// ASCII character display reference for display card suit symbols
//3 = heart symbol
//4 = diamond symbol
//5 = club symbol
//6 = spade symbol

int iNumberOfPlayers = 0;//Number of players in current game
int iPlayerCount[5];      //Integer array to holder each player's count
                                   //iPlayer[0] is always the dealer
int iHighestCount = 0;  //Highest count for a single game
int k, m;//integer loop counters


void initializeGame();
void deal();
void playGame();
char generateCard();
void generateDisplay();


void initializeGame()
{
if (iNumberOfPlayers == 0)
{
    cout << "No players in game, exiting program";
    Sleep(3000);
    exit(0);
}

cout << iNumberOfPlayers + "Joining the game with the dealer" << endl;
output[0][0] = 'Deal';
char name;
for (int i = 1; i <= iNumberOfPlayers; i++)
{
    output[i][0] = 'P ' + i;
}
for (int i = 0; i < 4; i++)
{
    for (int j = 0; j < 13; j++)
    {
        cCardDeck[i][j] = ' ';
    }
}

srand(GetTickCount());  //Seed the random-number generator
}

void deal()
{
for (k = 0; k <= iNumberOfPlayers; k++)
{
    for (m = 1; m <= 2; m++)
    {
        output[k][m] =  generateCard();
    }
}
tempDealerHand = output[0][0];
// output[0][0] = ? // to set dealer first hand to unknown
generateDisplay();
}

void playGame()
{
char HorS;
for (k = 1; k <= iNumberOfPlayers; k++)
{
    for (m = 3; m <= 5; m++)
    {
        cout << "Player " << k << " Would you like to Hit or Stay? Type H for Hit or anything else for Stay: ";
        cin >> HorS;
        if (HorS == 'H' || HorS == 'h')
        {
            output[k][m] = generateCard();
            generateDisplay();
        }
        else
        {
            break;
        }
    }
}
int dealerDraw = rand() % 3; // dealer will draw 0 to 3 cards;
for (int i = 0; i < dealerDraw; i++)
{
    output[0][i+3] = generateCard();
    generateDisplay();
}
}

char generateCard()
{
iSuit = rand() % 4;
iCard = rand() % 13;
if (iCard <= 8)
{
    cardName = iCard + 2;
}
else if (iCard == 9)
{
    cardName = 'J';
}
else if (iCard == 10)
{
    cardName = 'Q';
}
else if (iCard == 11)
{
    cardName = 'K';
}
else if (iCard == 12)
{
    cardName = 'A';
}
card[0][0] = Suit[iSuit],cardName;
return card[0][0];
}

void generateDisplay()
{ 
for (int i = 0; i < iNumberOfPlayers; i++)
{

    for (int j = 0; j < 8; j++)
    {
    cout << output[i][j];
    }
    cout << endl;
}
}

void main (void)
{


cout << "Do you want to play blackjack?";
cin >> cPlay;
Suit [0] = '0x03';
Suit [1] = '0x04';
Suit [2] = '0x05';
Suit [3] = '0x06';

cout << "Enter number of players: ";
cin >> iNumberOfPlayers;

while (true)
{
    initializeGame();
    deal();
    playGame();
}
}

编辑已更改,因此main位于底部,但仍然出现错误。

4 个答案:

答案 0 :(得分:2)

您可以在主要功能之前进行前向声明:

void initializeGame();
void deal();
void playGame();

void main (void)
{
  ...
}

void initializeGame()
{
  ...
}

void deal()
{
  ...
}

void playGame()
{
  ...
}

或将主函数定义放在文件的底部。

答案 1 :(得分:1)

您的更新代码似乎对我很好。这是屏幕截图。Screenshot

我无法找到代码中的问题。看来你正在使用Visual Studio。尝试清理解决方案(Build-&gt; Clean Solution),然后尝试重建代码。

答案 2 :(得分:0)

通常,您需要按照调用它们的顺序放置标识符(即函数定义):如果调用某些内容,则需要首先定义某些内容。在这种情况下,基本上颠倒你的程序将有助于你。

答案 3 :(得分:0)

在main()之前复制所有函数或者通常在.h文件中声明函数并在.cpp文件中定义它。