Original Post
This game is kind of like BlackJack, but with nothing fancy. Just random number 1-12 and you can hit or stand. Trying to get better than computer, who can get between 18 and 21. Most code is obvious, so I won't comment much. First card is always 0. Any help there? Also, the program won't add the cards correctly. I don't know what I should do to get that achieved. Any help is appreciated. Thanks alot! [Edited by - Killinger on April 9, 2005 11:10:46 PM]
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int card, currentcard, all, house, finish;
char hit;
int getcard() //getcard function
{
srand(time(NULL));
currentcard = rand() % 12 + 1; //getting random numbers
all = all + currentcard;
house = rand() % 4 + 18;
return 0;
}
int main()
{
all = 0;
all = getcard();
cout << "Welcome to 21!\n\n";
cout << "Your first card is " << all << "\n";
do
{
cout << "Would you like to (H)it or (S)tand?\n";
cin >> hit;
if (hit == 'h')
{
getcard();
cout << "Your card was " << currentcard << "\n";
cout << "Your sum is " << all << "\n";
if (all >= 21)
{
goto end;
}
}
}while (hit == 'h');
end:
{
cout << "The house had " << house << "\n";
if (house == all)
{
cout << "House wins ties...sorry!\n";
}
else if (all > 21)
{
cout << "You busted! House wins...\n";
}
else if (house >= all)
{
cout << "You lose!\n";
}
else
{
cout << "You win!\n";
}
return 0;
}
return 0;
}