C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 19th, 2008, 07:02 PM
CDCAREY089 CDCAREY089 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 9 CDCAREY089 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 25 m 52 sec
Reputation Power: 0
Second part of Program ( Black Jack )

This program is stating that the function "status()" is undefined even though it is defined in the class files.



These are the errors:


Code:
JJAC_B.cpp: In function `char hitStay()':
JJAC_B.cpp:94: `status' undeclared (first use this function)
JJAC_B.cpp:94: (Each undeclared identifier is reported only once for each 
   function it appears in.)
[J00134003@redhat3 J00134003]$ 





This is the header:



Code:
#ifndef JJAC_B_H
#define JJAC_B_H

class Blackjack  //Class for Blackjack Game
{
  public:

    void welcome();  //Beginning Message
    void blackjack_instructions();
    int draw();  //Lets user and dealer draw a random card from the deck
    char hitStay();  //Returns if the user wants to choose another card or stay
    void getWinner();
    void finish(); //End the game(ask the user to play again)
    void status(); //If the player is under 21, ask them to hit or stay
    void dealerFirst(); //Determine dealer's first card
    void playerFirst(); //Determine player's first card
    void playAgainDecide(); //Would the user like to play again
};

#endif





This is the cpp file: (Again just compiling for errors)



Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <fstream>
using namespace std;

#include "JJAC_B.h"

void Blackjack::welcome()
{
  int yesno;  //variable for user input

  ofstream outBlackJackFile( "blackjack.dat", ios::out );

  if( !outBlackJackFile )
  {
    cerr << "File cannot be opened" << endl;
    exit( 1 );
  }

  //Asks user if they want to play this game
  cout << "Welcome to Blackjack. If you are sure that you would like to play this game, please press 1. Otherwise, press 0.  ";
  cin >> yesno;

  //Calls the function that displays instructions
  while( yesno != 0 )
  {
        blackjack_instructions();
        //Asks user if they are sure they would like to exit
        cout << "Are you sure that you would like to leave this game? To exit press 0: ";
    cin >> yesno;
  }
}
//Displays instructions for blackjack
void Blackjack::blackjack_instructions()
{
        int useranswer;   //allows user to continue with game
        //Explanation of how to play Blackjack
        cout << "\nWelcome to Blackjack.  In this game,\n"
             << "cards will be randomly drawn for the deck\n"
             << "for as many times as you would like.\n"
             << "You will be playing against the dealer.\n"
             << "To win, you must get a score of 21 or beat the dealer's score.\n"
             << "If you draw too many cards and get higher than 21,\n"
             << "The dealer wins and vice versa for the dealer.\n"
             << "After each game, you will be told\n"
             << "whether or not you won, lost, or tied with the dealer.\n"
             << "If you would like to begin the game, press 1.\n"
             << "Otherwise, press 0: ";

        cin >> useranswer;

        //Calls either the function that runs or ends the blackjack game
        while( useranswer != 0 )
        {
        playerFirst();
        }
}

//Does the drawing of cards behind blackjack

void Blackjack::playerFirst()
{
//Determine the player's two cards
        int playertotal = 0;
        int card=draw();
        cout << "The card you drew is a " << card << " and a ";;
        playertotal+=card;
        card=draw();
        playertotal+=card;
        cout << card << ", so the total is " << playertotal << endl;

        status();
}

int draw()
{
        int card;

        card = 1+rand()%11;
        return card;
}

char hitStay()
{
  char move;


  cout << "\nWould you like to hit (h) or stay (s)? ";
        cin >> move;
        if (move=='h'||move=='H'||move=='s'||move=='S') //allows for lower or uppercase letters
        {
                status();
                return move;
        }
        else
        {
                cout << "Please enter h or s" << endl;
                hitStay();
        }
}

void Blackjack::status()
{
        int playertotal;
        int card;

        char move;
        while (playertotal<21)
        {
                move=hitStay();
                if( move =='s' ) //If the player wants to stay with the card they have...
                {
                        dealerFirst();
                }
                else if (move=='h') //If the player wants to add another card...
                {
                        playertotal+=draw();
                        cout << "\tThe card you drew is " << card << ".  Your total is " << playertotal << "."  << endl;
                }
        }
        finish();
}

void Blackjack::dealerFirst()
{
        int dealertotal;
        int playertotal;
        int card;
        card = draw();
        dealertotal += draw();
        cout << "Dealer drew: " << card << endl;
        if (playertotal>21)
        finish();
    while (dealertotal<=21)
    {
        dealertotal+=draw();
        cout << "\tDealer has" << card << ", total is " << dealertotal << "..." << endl;
        hitStay();
    }
}

void Blackjack::finish()
{
        getWinner();
        playAgainDecide();
}

void Blackjack::playAgainDecide()
{
        int playAgain;
        cout << "Would you like to play again (y/n) ";
        cin >> playAgain;
        if (playAgain=='Y' ||playAgain=='y') //allows for upper and lower case input
        {
        playerFirst();
        }
        else if (playAgain=='N' || playAgain=='n') //allows for upper and lower case input
        {
                cout << "Thanks for playing!\n\n" << endl;
                exit(0);
        }
        else
        {
                cout << "Please enter y or n. " << endl;
                playAgainDecide();
        }
}

void Blackjack::getWinner()
{
        int playertotal;
        int dealertotal;

        if (playertotal>21)
    {
        cout << "Sorry, you lose. The dealer wins this game." << endl;
    }
    else if (dealertotal>21)
    {
        cout << "The dealer loses with " << dealertotal << ", so you win this game." << endl;
    }
    else
        {
        if (playertotal>dealertotal)
        {
            cout << "Your " << playertotal << " beats the dealer's " << dealertotal << ". Congratulations!\n" << endl;
        }
        else if (playertotal<dealertotal)
        {
            cout << "Your " << playertotal << " loses to the dealer's " << dealertotal << ". Sorry!\n" << endl;
        }
        else
        {
            cout << "It is a tie! Both you and the dealer have " << playertotal << ".\n" << endl;
        }
    }

}






If you can aid in this situation. I would very much appreciate it.

Last edited by CDCAREY089 : November 19th, 2008 at 07:38 PM. Reason: Changed program around

Reply With Quote
  #2  
Old November 20th, 2008, 02:16 PM
Bobidybob's Avatar
Bobidybob Bobidybob is offline
Contributing Abuser
Click here for more information
 
Join Date: Apr 2007
Location: Starkville, MS
Posts: 318 Bobidybob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 10 h 22 m 49 sec
Reputation Power: 3
Send a message via AIM to Bobidybob
dont forget the Blackjack:: before your function definitions
__________________

Reply With Quote
  #3  
Old December 1st, 2008, 09:55 AM
CDCAREY089 CDCAREY089 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2008
Posts: 9 CDCAREY089 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 25 m 52 sec
Reputation Power: 0
Quote:
Originally Posted by Bobidybob
dont forget the Blackjack:: before your function definitions



Thanks. We appreciate the help.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Second part of Program ( Black Jack )


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
Stay green...Green IT