• 0

[C++] Blackjack Program


Question

Why isn't it exitting my while loop?

while( choice != 2 )

{

cout << "Hit or hold?" << endl;

cout << "1 = hit, 2 = hold" << endl;

cin >> choice;

if(choice == 1)

{

cout << pcard3 << endl;

playerscore = playerscore + pcard3;

cout << "Your current score: " << playerscore << endl;

if(playerscore == 21)

{

cout << "BLACKJACK!!! YOU WIN!!!" << endl;

playerwin++;

comploss++;

choice == 2;

}

if(playerscore > 21)

{

cout << "PLAYER BUST!" << endl;

compwin++;

playerloss++;

choice == 2;

}

}

cout << "Hit or hold?" << endl;

cin >> choice;

if(choice == 1)

{

cout << pcard4 << endl;

playerscore = playerscore + pcard4;

cout << "Your current score: " << playerscore << endl;

if(playerscore == 21)

{

cout << "BLACKJACK!!! YOU WIN!!!" << endl;

compwin++;

playerloss++;

choice == 2;

}

if(playerscore > 21)

{

cout << "PLAYER BUST!" << endl;

compwin++;

playerloss++;

choice == 2;

}

}

cout << "Hit or hold?" << endl;

cin >> choice;

if(choice == 1)

{

cout << pcard5 << endl;

playerscore = playerscore + pcard5;

cout << "Your current score: " << playerscore << endl;

if(playerscore == 21)

{

cout << "BLACKJACK!!! YOU WIN!!!" << endl;

compwin++;

playerloss++;

choice == 2;

}

if(playerscore > 21)

{

cout << "PLAYER BUST!" << endl;

compwin++;

playerloss++;

choice == 2;

}

}

cout << "Hit or hold?" << endl;

cin >> choice;

if(choice == 1)

{

cout << pcard6 << endl;

playerscore = playerscore + pcard6;

cout << "Your current score: " << playerscore << endl;

if(playerscore == 21)

{

cout << "BLACKJACK!!! YOU WIN!!!" << endl;

compwin++;

playerloss++;

choice == 2;

}

if(playerscore > 21)

{

cout << "PLAYER BUST!" << endl;

compwin++;

playerloss++;

choice == 2;

}

}

}

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

your my savior man. i cant thank you enough. i feel so stupid now because i know that, and spent a half hour trying to figure out what i was doing wrong....ugh im such a noob

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.