0 Replies - 1233 Views - Last Post: 30 March 2008 - 08:14 PM Rate Topic: -----

#1 TepidPenguin   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 29-March 08

Trying to get my first game to work

Post icon  Posted 30 March 2008 - 08:14 PM

I have been trying to get my first game to work. I have seen other posts on blackjack and couldn't get them to fit in correctly with what I'm trying to accomplish. I know that I'm probably missing pieces of code, thus the reason I'm asking for help. Here is what I have thus far:

#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) {
	while ((humanScore <= 21) && (humanScore < 0)) //Compare the scores to see who won
		if (humanScore == 21)
		{
			cout << "You have 21.  You win!" << endl;
		}
		else if ((humanScore < 21) && (humanScore > houseScore))
		{
			cout << "You have the closer hand to 21.  You win!"  << endl;
		}

//possible outcomes: human wins, computer wins, tie

}

int dealCards(int numberOfCards, string message){
	for (int i = 0; i <= numberOfCards; i++)  //This function deals the cards
	{
		//Random();
	}
		

}

void hit(int &playerScore){
	char wantCard = 'n';
	//int cardCount = 0;
	int cardTotal = 0;
		cardTotal = playerScore;

		cout << "Would you like another card?";		
		{while (wantCard == 'Y' || 'y')
		
			if ((cardTotal > 0 ) && (cardTotal <= 21)) 
			{
				//cardCount += 1;
				//cardTotal += Random();
				cout << " " << cardTotal << endl;
				cout << "Would you like another card?";
				cin >> wantCard;
			}
			else 
			{
				cout << "You are over 21. You loose!" << endl;
			}
			
		}
		

}

int Random(int lowerLimit, int upperLimit) {
	
//returns a random number within the given boundary
		 return 1 + rand() % (upperLimit - lowerLimit + 1);
}




Any help would be appreciated.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1