Can intialize a variable

The program runs but gets a bug at the end when I enter h,

heres the code

#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;

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;
}


return 0;
}

Please help me
"gets a bug"?

Can you be more descriptive?
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.
I think u need to intialize h="hit";
Again you are doing a mistake in comparing if(d=h).. it would be if(d==h){ } i guess...

Regards,
Farooq.
@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.
Topic archived. No new replies allowed.