- //Specification: This program plays a version of
-
//the card game of 21.
-
//A human player is pitted against the computer.
-
//The player who is the closest to 21 without
-
//going over wins the hand.
-
#include <iostream>
-
#include <ctime>
-
#include <string>
-
-
using namespace std;
-
-
//prototypes...
-
void play21(void);
-
int dealCards(int, string);
-
void hit(int &);
-
void determineWinner(int, int);
-
int Random(int, int);
-
-
-
void main(){
-
-
char keepPlaying = 'n'; //loop control variable
-
-
do {
-
play21();
-
-
//keep playing?
-
cout << "Do you want to play anouther hand (y/n)?";
-
cin >> keepPlaying;
-
} while(keepPlaying == 'Y' || keepPlaying == 'y');
-
}
-
-
void play21(void){
-
//play one hand of 21
-
-
//randomize the cards
-
srand((int) time(0));
-
-
// deal the cards
-
int person = dealCards(2, "Your Cards:");
-
cout << " = " << person << endl;
-
int house = dealCards(2, "Computers Cards:");
-
cout << " = " << house << endl;
-
-
// Ask if human wants a hit and keep hitting...
-
hit(person);
-
cout << endl;
-
-
//Determine if computer takes a hit
-
while ((house < person) && (house <= 21) && (person <= 21)) {
-
house += dealCards(1, "The Computer takes a card ");
-
cout << endl;
-
}
-
-
//show who won....
-
determineWinner(person, house);
-
}
-
-
void determineWinner(int humanScore, int houseScore) {
-
//Compare the scores to see who won
-
//Both the human and the house score totals are provided as arguments
-
//Display total scores and indicate winner
-
//possible outcomes: human wins, computer wins, tie
-
-
}
-
-
int dealCards(int numberOfCards, string message){
-
//This function deals the cards
-
//The number of cards to be dealt is provided as an argument
-
//A message indicating which player is receiving the cards is also
-
//given as an argument
-
//The player message and the cards dealt is displayed to the screen
-
//the total value of the dealt cards is returned
-
-
}
-
-
void hit(int &playerScore){
-
//This function asks the human if they want another card -- 'a hit'
-
//the player's score total is accumulated as they take cards
-
//the player can continue taking cards until they wish to stop or they exceed 21
-
//After a card is taken (use the dealCards function) the user's current total is displayed
-
//If the user goes over 21 'busted' is displayed
-
-
}
-
-
int Random(int lowerLimit, int upperLimit) {
-
//returns a random number within the given boundary
-
return 1 + rand() % (upperLimit - lowerLimit + 1);
-
}
3 3120
I'm sorry, but what exactly is your question?
Also, when you're posting code, you can use code-tags (put [code] in front of your code, and [/code] behind it, and it will be nicely formatted). Other guidelines like this and rules can be found in the faq.
-
//Specification: This program plays a version of
-
//the card game of 21.
-
//A human player is pitted against the computer.
-
//The player who is the closest to 21 without
-
//going over wins the hand.
-
#include <iostream>
-
#include <ctime>
-
#include <string>
-
-
using namespace std;
-
-
//prototypes...
-
void play21(void);
-
int dealCards(int, string);
-
void hit(int &);
-
void determineWinner(int, int);
-
int Random(int, int);
-
-
-
void main(){
-
-
char keepPlaying = 'n'; //loop control variable
-
-
do {
-
play21();
-
-
//keep playing?
-
cout << "Do you want to play anouther hand (y/n)?";
-
cin >> keepPlaying;
-
} while(keepPlaying == 'Y' || keepPlaying == 'y');
-
}
-
-
void play21(void){
-
//play one hand of 21
-
-
//randomize the cards
-
srand((int) time(0));
-
-
// deal the cards
-
int person = dealCards(2, "Your Cards:");
-
cout << " = " << person << endl;
-
int house = dealCards(2, "Computers Cards:");
-
cout << " = " << house << endl;
-
-
// Ask if human wants a hit and keep hitting...
-
hit(person);
-
cout << endl;
-
-
//Determine if computer takes a hit
-
while ((house < person) && (house <= 21) && (person <= 21)) {
-
house += dealCards(1, "The Computer takes a card ");
-
cout << endl;
-
}
-
-
//show who won....
-
determineWinner(person, house);
-
}
-
-
void determineWinner(int humanScore, int houseScore) {
-
//Compare the scores to see who won
-
//Both the human and the house score totals are provided as arguments
-
//Display total scores and indicate winner
-
//possible outcomes: human wins, computer wins, tie
-
-
}
-
-
int dealCards(int numberOfCards, string message){
-
//This function deals the cards
-
//The number of cards to be dealt is provided as an argument
-
//A message indicating which player is receiving the cards is also
-
//given as an argument
-
//The player message and the cards dealt is displayed to the screen
-
//the total value of the dealt cards is returned
-
-
}
-
-
void hit(int &playerScore){
-
//This function asks the human if they want another card -- 'a hit'
-
//the player's score total is accumulated as they take cards
-
//the player can continue taking cards until they wish to stop or they exceed 21
-
//After a card is taken (use the dealCards function) the user's current total is displayed
-
//If the user goes over 21 'busted' is displayed
-
-
}
-
-
int Random(int lowerLimit, int upperLimit) {
-
//returns a random number within the given boundary
-
return 1 + rand() % (upperLimit - lowerLimit + 1);
-
}
-
Banfa 9,065
Expert Mod 8TB
You have still not asked a question!
If you are having a prblem with the post code then you need to either post any compiler and linker errors you are getting or post a description of the runtime errors including, expected behaviour, actual behaviour, input data, output.
Additionally you need to have the courtesy to actually ask for the help you require.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sam |
last post by:
Hey all,
I want to create a computerised version of this game, though I'm not
really sure how to go about it. For those who don't know how the game
works, here's my attempt at a brief...
|
by: theodp |
last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml
Microsoft Patents Saving The Name Of A Game
Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM
from the...
|
by: jar13861 |
last post by:
Create a game in a 3x3 HTML table that works as follows:
* The goal of the game is to beat the computer by scoring more
points than the computer.
* The game starts when a hidden random number...
|
by: JNeko |
last post by:
Hello all, awesome site! I guess I am technically not a beginner in JAVA, but from my code you would not realize it! I don’t expect anyone to help me with this, but I figure I might as well as try...
|
by: HighBuddha |
last post by:
Hello, i have a question about game trees. I've been given an assignment in class (highschool) and the assignment is to write a program the simulates The Game Of Eight. The game runs like this:
...
|
by: Leiram |
last post by:
I am trying to write a game where there is 13 stones and you play against the computer to make sure that you don't take the last stone. You or the computer (depending on the turn) is allowed to take...
|
by: LilMeechc20 |
last post by:
Hello,
I have a group assignment that I have to do. We have to write a Tic Tac Toe game. One person in my group has managed to write the code for a multiplayer (human -vs- human) game and I...
|
by: imran akhtar |
last post by:
i have a balckjack code, which does not seem to run, in python, it comes up with syntax error, i have try sortng it out. does not seem to work. below is my code, if anyone can work out wht wrong...
|
by: Shark2026 |
last post by:
Hi there I need to make a Craps game for my class. Here are the parameters for it.
In the game of craps, a pass line bet proceeds as follows. Two six-sided dice are rolled; the first roll of the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| | |