Computer Forums HELP::acehigh game problem in cpp

 09-15-2005, 03:50 AM #1 Solid State Member     Join Date: Jul 2005 Posts: 9 HELP::acehigh game problem in cpp hello all, i am working on a really simple game that doesn't require any input from the user, except to run or end the program, and i am completely stuck. i could really use some help here. i have to use user-defined functions and I can't figure out how to call each of them in main(). the program needs to display two cards in numerical form from 2 to 11 for the player and the dealer, then total the two cards. If the player is over 21 he loses, and same for the dealer; but if the dealer is under 17 he must draw again. the code is below, let me know if i need to give more info Code: ```#include #include #include using namespace std; int randomDraw(int card); //returns random number from 2 to 11 bool isBust(int hand); //returns true if the value of hand exceeds 21. void playerWins(int handP); //displays the fact player won. void dealerWins(int handD); //displays the fact dealer won bool mustDraw(int dealer); //returns true if the value of dealers hand is less than 17. int drawoneCard(char[], int, bool); //returns true if the value of dealers hand is less than 17. int main() { cout << "WELCOME TO MY ACE-HIGH GAME " << endl; //randomDraw(int card); //bool isBust(int hand); //void playerWins(int handP); //void dealerWins(int handD); //bool mustDraw(int dealer); //int drawoneCard(char[], int, bool); return 0; } //returns randomly generated card value from 2 to 11. int randomDraw(int card) { srand (time(NULL)); card = (rand()%10+2); return(card); } //returns true if the value of hand exceeds 21. bool isBust(int handP) { if(handP>21) return true; else return false; } //displays the fact player won. void playerWins(int handP) { cout << "Player Wins " << endl; } //displays the fact dealer won void dealerWins(int handD) { cout << "Dealer Wins " << endl; } //returns true if the value of dealers hand is less than 17. bool must_draw(int dealer) { if(dealer<17) return true; else return false; } //returns true if the value of dealers hand is less than 17. //int drawoneCard(char[], int , bool) //{ // return; //}``` __________________ __________________
 10-04-2005, 01:18 PM #2 Baseband Member     Join Date: Jun 2004 Posts: 89 Re: HELP::acehigh game problem in cpp Hi, sorry I didn't see your post earlier. You call a function defined as void foo(void) by the line Code: ```//other stuff here foo(); //rest of stuff here``` Where the type of arguments is defined as follows, the arguments numbers and types follow the declaration and definition. Return types (the type on the left) is never used in calling a function. Some examples are shown below. Code: ``` // Assuming variables that match types defined here. void Add(int a, int b); Add(1, 1); Add(Some_int, Other_int); float divide_one(double num1, double num2); divide_one(Flotsam, Jetsam); char * Stringer(char * A_line, char * Another_line); stringer(ptr_first, ptr_second);``` To capture and use the return value from a function, you must write an assignment operation into the statement calling the function. A brief example is shown below. Code: ``` int a = 7, b = 13, Sum; int Addition(int x, int y); // Somewhere else in the code... int Addition(int x, int y){ return(x+y); } //Somewhere we want to call Addition and assign the return. Sum = Addition(a, b); //Addition will return the results and they will be assigned //into Sum. So Sum now carries a value of 20.``` I hope you'll find these values useful. __________________ /*What does not kill us, makes us drink far too much caffeine*/