DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   need some help (http://www.daniweb.com/forums/thread151194.html)

cerb63 Oct 14th, 2008 8:42 pm
need some help
 
I need some help trying to figure out the void statements for my project and also getting this second program Factorial Program without recursion to work right.
#include <iostream>
#include "PROJECT_13_1_H.h"


using namespace std;
int main()
{
  bool houseHasBigAce = false;
  srand(time(0));
  int houseHand = drawOpenHouseCard(houseHasBigAce); 

  cout<<endl<<endl;
  cout<<"Welcome to the game of BlackJack!"<<endl;
  cout<<"*********************************"<<endl<<endl;
 
  int playerHand = buildPlayerHand();
  announceResult(PLAYER_SIDE, playerHand);
 
  if (playerHand <=21)
  {
    houseHand = buildHouseHand(houseHand, houseHasBigAce);
    announceResult(HOUSE_SIDE, houseHand); 
  }
  whoWins(playerHand, houseHand);
  system("pause");
  return 0;
}
int buildPlayerHand()
{
    int theHand = 0;
    bool hasBigAce = false;
   
    cout<<"The dealer will now deal cards to the player..."<<endl;
    for (int i=0; i<2; i++)
    {
        theHand= drawAndAddCardToHand(theHand, hasBigAce);
    }
    bool playerHolds = false;
    while (theHand < 21 && !playerHolds)
    {
          playerHolds = isPlayerHolding(theHand);
          if(!playerHolds)
            theHand = drawAndAddCardToHand(theHand, hasBigAce);               
    }
    return theHand;
}       
bool isPlayerHolding(int theHand)
{
    char answer;
    cout<<"Do you wish to hold on "<<theHand<<"? Type Y - for Yes or N - for No."<<endl;
    do
    {
        cin>>answer;
        answer = toupper(answer);
    }while (answer != 'Y' && answer != 'N');
    return (answer == 'Y');
}   
int drawOpenHouseCard(bool & hasBigAce)
{
    cout<<"The dealer will draw an open card for the house"<<endl;
    return(drawAndAddCardToHand(0, hasBigAce));
}
int buildHouseHand(int theHand, bool & hasBigAce)
{
    while (theHand < 17)
    {
      cout<<"The house draws on "<<theHand<<" and receives "<<endl;
      theHand = drawAndAddCardToHand(theHand,hasBigAce);
    }
    return theHand;
}     
   
int drawAndAddCardToHand(int theHand, bool &hasBigAce)
{
    int theCard = drawOneCard();
    announceCard(theCard);
    theHand = addCardToHand(theHand, theCard, hasBigAce);
    announceHand(theHand);
    return theHand;
}
int drawOneCard()
    {return (rand() % 13 + 1);}
   
int addCardToHand(int theHand, int theCard, bool &handContainsAce11)
{
    if (theCard > 10)
      theHand +=10;
    else
        if(theCard ==1 && theHand < 10)
        {  theHand += 11;
            handContainsAce11=true;
        }
        else
            theHand+=theCard;
           
    if (theHand > 21 & handContainsAce11)
    {
        theHand -=10;
        handContainsAce11 = false;
    }
    return theHand;
}       
                 
//void announceCard(int);
//void announceHand(int);
//void announceResult(bool, int);
//void whoWins(int, int);
second program
#include <iostream>
using namespace std;

int find_fib(int);   

int main(int argc, char* argv[])
{
  int n=0, result=0;
  cout << "Enter the position in the sequence to find: ";
  cin >> n;
  result = find_fib( n );
  cout << result << " is the " << n << "th Fibonacci sequence number" << endl;
  system("pause");
  return 0;
}

int find_fib( int n )
{
  if(n < 3)
    return 1;
  else
    return( find_fib(n - 2) + find_fib( n - 1 ) );
}


All times are GMT -4. The time now is 11:23 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC