I'm trying to make this program work like a game of BlackJack. However, the program will not listen to me when I try to end the loop. does anyone have any sugestions on how to fix this program?

#include <iostream>
#include <ctime>

using namespace std;

double card = 0;
double pHand = 0;
double dHand = 0;
int YN = 0;
bool val = true;

int main()
{
  srand( time( NULL ) ); 
  
  
  card = ( rand() %13) + 1; // opening hand
  cout << card << " has been drawn" <<endl;
  pHand = pHand+card;
  cout << "player has " << pHand<< endl;
  
card = ( rand() %13) + 1; 
  cout << card << " has been drawn" <<endl;
  dHand = dHand+card;
  cout << "dealer has " << dHand<< endl;
  
  card = ( rand() %13) + 1; 
  cout << card << " has been drawn" <<endl;
  pHand = pHand+card;
  cout << "player has " << pHand<< endl;
  
  card = ( rand() %13) + 1; 
  cout << card << " has been drawn" <<endl;
  dHand = dHand+card;
  cout << "dealer has " << dHand<< endl;

  
  
  while (val = true)
  {
  cout << "Would you like another card?\n 1.Hit me \n 2.No Thanks \n";
  cin >> YN;  
  
  if (YN = 1)
  {
   val = true;
  }
  
  if (YN != 1)
  {
   val = false;
  }
  
  if (val = true)
  {
   cout << "Very well\n";
   card = ( rand() %13) + 1; 
   cout << card << " has been drawn" <<endl;
   pHand = pHand+card;
   cout << "player has " << pHand<< endl;
  }
  
  if (val = false)
  {
while (dHand <= 17)
  {
   card = ( rand() %13) + 1; 
   cout << card << " has been drawn" <<endl;
   dHand = dHand+card;
   cout << "dealer has " << dHand<< endl; 
  }
}
}  
   
  

  system ("pause");
  return 0;                 
}

Please help if you can.

val = true sets the content of val to true. val==true checks the content of value.

They are two very different things! In your while loop and in the two if statements you need the second, so just fix it and your loop will work as expected :)

This question has already been answered. Start a new discussion instead.