| | |
need some help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 9
Reputation:
Solved Threads: 0
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.
second program
C++ Syntax (Toggle Plain Text)
#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);
C++ Syntax (Toggle Plain Text)
#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 ) ); }
Last edited by Narue; Oct 15th, 2008 at 9:18 am. Reason: added code tags
![]() |
Other Threads in the C++ Forum
- Previous Thread: Help with reading bitmap
- Next Thread: confusing parse error
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





