Hyena
October 20th, 1999, 07:14 AM
okay, heres the deal- im trying to organize my main program, blackjack.ccp, by breaking it up into multiple programs. i've been okay with header files, but someone suggested the other day that i use another .ccp file. heres what i tried so far-
*************************************************
********blackjack.ccp****************************
*************************************************
#include <iostream.h>
#include "deck.h"
#include "bool.h"
#include "rand.h"
#include "function.h"
//-----------------------function prototypes-----------------------------
void noRepeat(int x);
void cHand(int& cTotal, int& cardCounter);
//-----------------------------------------------------------------------
//-----------------------global variables-------------------------------
int Deck[52];
deck d;
BOOL haveAce = FALSE;
//----------------------------------------------------------------------
//======================================================================
//-------------------------------MAIN-----------------------------------
//----------------------------------------------------------------------
void main()
{
char ans;
do {
d.makeDeck();
randomize();
int cardCounter = 0;
Deck[0] = rand() % 52;
for(int x = 1; x < 52; x++)
{
Deck[x] = rand() % 52;
noRepeat(x);
}
int pTotal, cTotal, hitOrStay;
pTotal = cTotal = hitOrStay = 0;
cout << "You draw ";
hand(pTotal, cardCounter, haveAce);
hand(pTotal, cardCounter, haveAce);
if(pTotal == 21)
{
cout << "Blackjack. You win\n";
}
while((pTotal < 22) && (ans != 's') && (ans != 'S'))
{
cout << "You have " << pTotal << endl;
cout << "\n<H>it or <S>tay? ";
cin >> ans;
if((ans == 'h') || (ans == 'H'))
{
hand(pTotal, cardCounter, haveAce);
if((haveAce == TRUE) && (pTotal > 21))
{
pTotal -= 9;
haveAce = FALSE;
}
}
}
cout << endl;
if(pTotal > 21)
{
cout << "You loose\n";
pTotal = 0;
}
cout << "\nComputer draws ";
cHand(cTotal, cardCounter);
cHand(cTotal, cardCounter);
while(cTotal < pTotal)
{
cHand(cTotal, cardCounter);
}
if(((cTotal < 22) && (pTotal < cTotal)) || (cTotal == 0))
{
cout << "The computer wins. Try again.\n";
}
else
{
cout << "You win, way to go\n";
}
cout << "\n\nPlay again? ";
cin >> ans;
} while((ans == 'y') || (ans == 'Y'));
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//=======================================================================
//------------------------------computer's hand----------------------------
void cHand(int& cTotal, int& cardCounter)
{
int temp = 0;
temp = Deck[cardCounter];
if(temp > 35)
{
cout << d.card[temp].face;
}
else cout << d.card[temp].value;
cout << " of " << d.card[temp].suit << "\n";
if(d.card[temp].face == "Ace")
{
haveAce = TRUE;
if((cTotal + 11) < 22)
{ d.card[temp].value = 11; }
else { d.card[temp].value = 1; }
}
cardCounter++;
cTotal += d.card[temp].value;
}
//-------------------------------------------------------------------------
//-------------------------no repeat---------------------------------------
void noRepeat(int x)
//shuffles deck (randomizes 0 - 51 with no repitions)
{
Deck[x] = rand() % 52;
for(int y = 0; y < x; y++)
{
if(Deck[x] == Deck[y])
noRepeat(x);
}
}
//-----------------------------------------------------------------------
**************************************************
**************************************************
*************function.h***************************
**************************************************
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
void hand(int& pTotal, int& cardCounter, BOOL& haveAce);
#endif
*************************************************
**************************************************
**********function.ccp****************************
**************************************************
#include "deck.h"
#include <iostream.h>
#include "bool.h"
extern int Deck[52];
deck dd;
//------------------------------player's hand-----------------------------
void hand(int& pTotal, int& cardCounter, BOOL& haveAce)
{
int temp = 0;
temp = Deck[cardCounter];
if(temp > 35)
{
cout << dd.card[temp].face;
}
else cout << dd.card[temp].value;
cout << " of " << dd.card[temp].suit << "\n";
if(dd.card[temp].face == "Ace")
{
haveAce = TRUE;
if((pTotal + 11) < 22)
{ dd.card[temp].value = 11; }
else
{ dd.card[temp].value = 1; }
}
cardCounter++;
pTotal += dd.card[temp].value;
}
//-------------------------------------------------------------------------
this is what i have and i still keep getting 'unresolved external errors.' this is my first time working with multiple ccp files, so i dont know how to fix what im doing so please help.
*************************************************
********blackjack.ccp****************************
*************************************************
#include <iostream.h>
#include "deck.h"
#include "bool.h"
#include "rand.h"
#include "function.h"
//-----------------------function prototypes-----------------------------
void noRepeat(int x);
void cHand(int& cTotal, int& cardCounter);
//-----------------------------------------------------------------------
//-----------------------global variables-------------------------------
int Deck[52];
deck d;
BOOL haveAce = FALSE;
//----------------------------------------------------------------------
//======================================================================
//-------------------------------MAIN-----------------------------------
//----------------------------------------------------------------------
void main()
{
char ans;
do {
d.makeDeck();
randomize();
int cardCounter = 0;
Deck[0] = rand() % 52;
for(int x = 1; x < 52; x++)
{
Deck[x] = rand() % 52;
noRepeat(x);
}
int pTotal, cTotal, hitOrStay;
pTotal = cTotal = hitOrStay = 0;
cout << "You draw ";
hand(pTotal, cardCounter, haveAce);
hand(pTotal, cardCounter, haveAce);
if(pTotal == 21)
{
cout << "Blackjack. You win\n";
}
while((pTotal < 22) && (ans != 's') && (ans != 'S'))
{
cout << "You have " << pTotal << endl;
cout << "\n<H>it or <S>tay? ";
cin >> ans;
if((ans == 'h') || (ans == 'H'))
{
hand(pTotal, cardCounter, haveAce);
if((haveAce == TRUE) && (pTotal > 21))
{
pTotal -= 9;
haveAce = FALSE;
}
}
}
cout << endl;
if(pTotal > 21)
{
cout << "You loose\n";
pTotal = 0;
}
cout << "\nComputer draws ";
cHand(cTotal, cardCounter);
cHand(cTotal, cardCounter);
while(cTotal < pTotal)
{
cHand(cTotal, cardCounter);
}
if(((cTotal < 22) && (pTotal < cTotal)) || (cTotal == 0))
{
cout << "The computer wins. Try again.\n";
}
else
{
cout << "You win, way to go\n";
}
cout << "\n\nPlay again? ";
cin >> ans;
} while((ans == 'y') || (ans == 'Y'));
}
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//=======================================================================
//------------------------------computer's hand----------------------------
void cHand(int& cTotal, int& cardCounter)
{
int temp = 0;
temp = Deck[cardCounter];
if(temp > 35)
{
cout << d.card[temp].face;
}
else cout << d.card[temp].value;
cout << " of " << d.card[temp].suit << "\n";
if(d.card[temp].face == "Ace")
{
haveAce = TRUE;
if((cTotal + 11) < 22)
{ d.card[temp].value = 11; }
else { d.card[temp].value = 1; }
}
cardCounter++;
cTotal += d.card[temp].value;
}
//-------------------------------------------------------------------------
//-------------------------no repeat---------------------------------------
void noRepeat(int x)
//shuffles deck (randomizes 0 - 51 with no repitions)
{
Deck[x] = rand() % 52;
for(int y = 0; y < x; y++)
{
if(Deck[x] == Deck[y])
noRepeat(x);
}
}
//-----------------------------------------------------------------------
**************************************************
**************************************************
*************function.h***************************
**************************************************
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
void hand(int& pTotal, int& cardCounter, BOOL& haveAce);
#endif
*************************************************
**************************************************
**********function.ccp****************************
**************************************************
#include "deck.h"
#include <iostream.h>
#include "bool.h"
extern int Deck[52];
deck dd;
//------------------------------player's hand-----------------------------
void hand(int& pTotal, int& cardCounter, BOOL& haveAce)
{
int temp = 0;
temp = Deck[cardCounter];
if(temp > 35)
{
cout << dd.card[temp].face;
}
else cout << dd.card[temp].value;
cout << " of " << dd.card[temp].suit << "\n";
if(dd.card[temp].face == "Ace")
{
haveAce = TRUE;
if((pTotal + 11) < 22)
{ dd.card[temp].value = 11; }
else
{ dd.card[temp].value = 1; }
}
cardCounter++;
pTotal += dd.card[temp].value;
}
//-------------------------------------------------------------------------
this is what i have and i still keep getting 'unresolved external errors.' this is my first time working with multiple ccp files, so i dont know how to fix what im doing so please help.