我的 C++ 代码出现错误。我通常是一名 Java 开发人员,但我正在学习 C++ 课程,以便在我的编程能力方面更加广泛。无论如何,当我尝试构建此解决方案时,我得到了错误
1>c:\users\westlakes\documents\visual studio 2010\projects\blackjack\blackjack\playblackjack.cpp(81): error C3861: 'initializeGame': identifier not found
1>c:\users\westlakes\documents\visual工作室 2010\projects\blackjack\blackjack\playblackjack.cpp(82): error C3861: 'deal': identifier not found
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 位于底部,但仍然出现错误。