CODE
#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 another 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) {
// Chooses winner
if ((houseScore > humanScore) && (houseScore >= 21) && (humanScore < houseScore)) { //Gets computers score
cout << "Computer Wins ";
if ((humanScore > houseScore) && (humanScore >= 21) && (houseScore < humanScore)) //Gets user score
cout << "You Win ";
else if ((houseScore == humanScore) && (humanScore == houseScore));
cout << ("Tie Game ")<< endl;
//end ifs
//end function
return;
}
// Deals the cards
int dealCards = int numberOfCards, string message;{ [error:type'int'unexpected]
int ret_val = (0, val); [error:'val'undeclared identifier]
int cards = numberOfCards; [error:'numberOfCards'undeclared identifier]
int numberOfCards = 0;
int val = 0;
cout << message; [error:'message':undeclared identifier]
while(cards--){
// Values from 1 to K
val = Random(0,14);
if( val > 10 ) val = 10;
if( val == 1 ) val = 11;
cout << val;
if(cards)
cout << ",";
ret_val+=val;
}
return;
}
//Want a hit?
void hit(int &playerScore){ [error:'hit':localfunctiondefinitions are illegal]
int playerScore = val;
int playerScore = 0.0;
char hit = ' ';
double = choice;
cout << "Do you want a hit (y/n)?";
cin >> ' ';
}do while (hit == 'Y' || hit == 'y'); [error:noconversionfrom'int'to'void'(cdecl*)(int&)]
person += dealCards(1); // Deals one card [error:syntax error:identifier'person']
if ((playerScore < 21)); [error:undeclared identifier]
cout << val; // Displays score
cout << "Do you want another hit (y/n)?";
cin >> endl;
do while (playerScore < 21) || (hit !='n');
if ((playerScore > 21);
cout << val << "Busted" << endl;
//end while
//end ifs
//end function
}
return ret_val;
}
int Random(int lowerLimit, int upperLimit) {
//returns a random number within the given boundary
return 1 + rand() % (upperLimit - lowerLimit + 1);
}
I've been working on this since 3 a.m. I have narrowed it down from 34 errors to 13 can someone please explain the errors to me. I truely don't understand.
This post has been edited by izm94303: 3 Aug, 2008 - 05:22 PM