Hi guys,
I am new to c++ but I have an issue with my program.
basically I have a blackjack program (that I think everyone starts with?) and I am trying to test my randomly filled array by printing the whole thing, rows and columns.
however, when I run the function I have it doesn't print anything. could someone give me a hand to tell me what I'm doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12
void fill(int i, int j, int cCardDeck[4][14]) //intialize array with random numbers
{
srand(time(NULL));
for (i=0; i<4; i++)
{
for (int j=0; j<14; j++)
{
cCardDeck[i][j] = rand() % 14;
}
}
void print();
};
This is the print function
1 2 3 4 5 6 7 8 9 10 11
void print(int i, int j, int cCardDeck[4][14]) //print array to test in rows and columns
{
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 14; ++j)
{
cout << cCardDeck[i][j] << ' ';
}
cout << endl;
}
}
any and all help is much appreciated. I feel like im so close but missing one silly thing.
Removing the parameters gave me errors before, but now apparently i fixed whatever really was causing the errors.
however now I have adjusted to this and it still doesnt print.
This is my full code. pardon the mess, the professor has declared what the variables should be called.
// Programmer: (Ian Dalton)
// 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>
usingnamespace std;
char cPlay; //answer to yes or no (wanna play?)
int iPlayerCount; //self explanatory
int cCardDeck[4][14]; //array representing the card deck
//int iCard; //Card array index
int iNumberOfDraws = 0; //Number of rounds of card draws
//int iSuit; //Suit array index
//0 = diamonds //declare which suit the card has, eventually
//1 = hearts
//2 = clubs
//3 = spades
int iNumberOfPlayers = 0; //Number of players in current game
//ignore this stuff until these variables are needed
/**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
srand(GetTickCount()); //Seed the random-number generator
**/
//main loop (play?)
int main()
{
cout << "Wanna play a game of Blackjack? Y/N" << endl;
cin >> cPlay;
if ( (cPlay == 'y') || (cPlay == 'Y') )
{
cout << "Great! How many people are playing?" << endl;
cin >> iNumberOfPlayers;
cout << "Excellent. Let me deal for the ";
cout << iNumberOfPlayers;
cout << " of you" << endl;
void fill();
}
else
{
cout << "Then why did you open this, ya goof? See you later!" << endl;
system ("PAUSE");
}
system ("PAUSE");
}
void print()
{
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 14; ++j)
{
cout << cCardDeck[i][j] << ' ';
}
cout << endl;
}
}
void fill()
{int i;
for (i=0; i<4; i++)
{
for (int j=0; j<14; j++)
{
cCardDeck[i][j] = j;
}
}
print();
}
line 57 - remove the return type in the function call
if you're going to have function definitions after the main function where they're called, there should be a function prototype before main so the compiler knows what they are