GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Feb-2008, 23:58
shampaynes shampaynes is offline
New Member
 
Join Date: Feb 2008
Posts: 4
shampaynes is on a distinguished road

Need Help With Program


my teacher gave me an assignment to complete the blackjack program but I have little understanding of it. I have the majority of it but i'm missing pieces.

NOTE: All of the sections where it says TO DO are the missing pieces.
PLEASE HELP.

CPP / C++ / C Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define HEARTS 1
#define CLUBS 2
#define SPADES 3
#define DIAMONDS 4

#define ACE 1
#define JACK 11
#define QUEEN 12
#define KING 13

/////////////////////////////////////////////////////////////////////
void print_card(int rank, int suit)
{
switch (suit)
{
case DIAMONDS:
printf("Diamonds\n");
break;
case SPADES:
printf("Spades\n");
break;
case CLUBS:
printf("Clubs\n");
break;
case HEARTS:
printf("Hearts\n");
break;

default:
printf("\n");
}

switch (rank)
{ 
case ACE:
printf("ACE\n");
break;
case JACK:
printf("JACK\n");
break;
case QUEEN:
printf("QUEEN\n");
break;
case KING:
printf("KING\n");
break;

default:
printf("\n");
}

}

int test_print(void)
{
print_card(JACK, SPADES); // Jack of Spades
print_card(ACE, HEARTS); // Ace of Hearts
print_card(4, DIAMONDS); // 4 of Diamonds
print_card(6, CLUBS); // 6 of Clubs
return 0;
}

void choose_card(int& rank, int& suit)
{
rank=rand() % 13+1;
suit=rand() % 4+1;

}

int test_choose(void)
{
srand(time(NULL));
int r, s;
for(int i = 0; i < 10; i++)
{
choose_card(r, s);
print_card(r, s);
}
return 0;
}

/* This function should return the score of a card in the game of
blackjack. Numeric cards are simple; their scores are the same as
their rank. (Three of clubs worth three points.) Face cards
(Jack, Queen, King) are each worth 10 points, and the Ace is worth
11 points. (In the real game, an Ace may be used either as 1 or as
11 points, but that makes scoring more complicated so just treat it
as 11 points for nom.) */
int score_card(int rank)
{
// TO DO
return 0;
}


int test_score(void)
{
printf("%d\n", score_card(ACE)); // 11
printf("%d\n", score_card(QUEEN)); // 10
printf("%d\n", score_card(4)); // 4
printf("%d\n", score_card(KING)); // 10
printf("%d\n", score_card(2)); // 2
return 0;
}


void ignore_to_end_of_line(void)
{
char ignored;
do {
scanf("%c", &ignored);
} while( ignored != '\n' );
}

/* This function should print the prompt (the 'char*' just means we're
passing a double-quoted string; you can print it in printf with
"%s". The function should then read a character and return true
or false. If the user typed something wrong, then print an error
message and try again. The function should at least accept upper-
and lower-case y/n. */

bool ask_yes_no(char* prompt)
{
char answer;
printf("%s (y/n)? ", prompt);
scanf("%c", &answer);
ignore_to_end_of_line();
// TO DO..
return false;
}

int test_ask(void)
{
if( ask_yes_no("Does this work") )
{
printf("You said YES\n");
}
else
{
printf("You said NO\n");
}
return 0;
}


int play_one_hand(void)
{
bool hit = true;
int score = 0;
int num = 0;
// TO DO... 
return score;
}


void print_final_result(int score)
{
printf("Your final score is %d", score);
if(score == 21)
{
printf(" (BLACKJACK)");
}
else if(score > 21)
{
printf(" (BUST)");
}
printf("\n");
}


int main(void)
{
srand(time(NULL));
printf("WELCOME TO BLACKJACK.\n");
do {
print_final_result(play_one_hand());
} while(ask_yes_no("Play again"));
return 0;
} 
  #2  
Old 17-Feb-2008, 16:28
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,496
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Need Help With Program


Quote:
Originally Posted by shampaynes
my teacher...
If you would read the Guidlines for posting requests for help, you might notice the following (among other important items):

Quote:
Originally Posted by Guidelines for posting requests for help
...We cannot help you if you show us nothing you've attempted. Posting just your assignment/problem description is likely to get a few snide comments and nothing more...

I'll forego the snide comment part and ask a couple of questions:

In the "ToDo" sections, what have you tried?

What kind of help would you like to get from us?

Regards,

Dave
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 10:13
Text-Based Roulette Game mfm1983 C++ Forum 5 29-Nov-2006 12:20
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 03:48
Pipeline freeze simulation darklightred C++ Forum 6 27-Jul-2006 19:37
How to read particular memory location ? realnapster C Programming Language 10 10-May-2006 09:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:52.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.