int main()
{
cout <<"**********************\n"
<< "***BLACKJACK MANIA!***\n"
<< "**********************\n"
<< endl;
cout << "Please input your First name." << endl;
string A;
cin >> A;
cout << "Thank you " << A << " for playing BlackJack Mania!" <<
"\n\n";
cout << A << " your first two cards will be dealt to you." <<
" You may then choose to hit and receive another card or stay with the cards you have." <<
"\n\n";
srand((unsigned)time(0));
int random_num1, B;
for(int index=0; index<1; index++) {
random_num1 = (rand()%11)+1;
cout << A << " your card is: " << random_num1 << endl;
}
srand((unsigned)time(0));
int random_num2, C;
for(int index=0; index<1; index++) {
random_num2 = (rand()%10)+1;
cout << A << " your card is: " << random_num2 <<
"\n\n";
}
cout << A << " your total is: " << random_num1 + random_num2 <<
"\n\n";
cout << "You know have the decision to choose to hit and recieve another card or stay with the few cards you have." <<
" If you want to hit please type, hit. If you want to stay please type, stay." <<
"\n\n";
char d,h,s;
cin >> d;
if(d=h){
srand((unsigned)time(0));
int random_num3, E;
for(int index=0; index<1; index++) {
random_num3 = (rand()%10)+1;
cout << A << " your card is: " << random_num3 <<
"\n\n";
}
cout << A << " your new total is: " << random_num1 + random_num2 + random_num3 << endl;
}
The program runs but then it says "Run time check Failure #3" The variable 'h' is being used without being initialized.
it says that i have not allocated space for the variable
Code tags, please. And the problem is that you have declared h, then you try to use its value, which is garbage because you haven't assigned anything to it yet.
@farooq: You are correct about the if statement; however h is a char so you cannot assign a string to it as you have described.
@OP: I think I see what you were attempting to do; do bother making a variable to hold the 'h' to compare against unless it's going to be a constant. Just compare against the value itself.