Breaking out of do while loop??
Hello, I am not being able to get out of my do..while loop. Can someone please help? When the sum is more than 22, I want the program to break out of loop and prompt "Busted!". Thanks is advance. #include<cstdlib> #include<ctime> #include <iostream> using namespace std; int main() { int sum; char tryagain; cout<< ">" << " "<< "In the card game named 'Blackjack' players get two cards to start with, and then they are asked whether or not they want more cards. Players can continue to take as many cards as they like. Their goal is to get as close as possible to a total of 21 without going over. Face cards have a value of 10. Dealer has 18." << endl << endl; srand(time(NULL)); int card1=rand()%10+1; int card2=rand()%10+1; cout<< endl<< ">" << " " << "Your cards are"<<" " << card1<<" " << "and"<< " " << card2; sum = card1 + card2; cout << endl << ">" << " "<< "Total:"<< " " <<sum; cout << endl<< endl<< ">" << " "<< "Do you wish to pick another card? (y/n)"; cin>> tryagain; while(tryagain == 'y' ){ do{ srand(time(NULL)); int newcard = rand()%10+1; cout << ">" << " " << "New card:"<< " "<< newcard; sum+= newcard; cout <<endl << ">" << " " << "Total:" << sum<< endl; if(sum > 21){ break; } cout << endl <<">" << " " <<"Do you want to pick another card? (y/n)"; cin>> tryagain; }while(tryagain == 'y'); } if (sum == 18){ cout<< "It was a draw!"; } if(sum < 18){ cout<< "You lose!"; } if(sum > 18 && sum < 21){ cout<< "You win!"; } if(sum > 21){ cout<< "Busted!"; } return 0; }