I'm trying to make a blackjack game but I'm having a little trouble with a do/while loop.
Maybe a do/while loop isn't the right kind of loop to be using? I dunno, you tell me.
Here's the code:
#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>
#include <ctime>
using namespace std;
int number;
char ans;
char Ans;
int rand(); //number between 1 and 10;
int main(int argc, char *argv[])
{
cout << "Welcome to Blackjack! \n";
cout << "\n"; // these are for double spacing.
system ("pause ");
cout << "\n";
srand(time(NULL));
cout << "You've been dealt a(n) " << rand() % 10 + 2 <<"\n";
cout << "\n";
cout << "To hit, press 1, to stay press 2. \n";
cout << "\n";
cin >> ans; cout <<"\n";
if(ans=='1'){
cout << "You're now at a(n) " << rand() % 10 + 1 + rand() % 10 + 2 << "\n";
cout <<"\n";
if(rand()==21){
cout <<"BLACKJACK!\n";
cout << "\n";
cout <<" Do you want to play again?\n";
cout << "\n";
cin >> Ans;
}
}
I need to get the program to start over if they choose yes after getting a blackjack. Any ideas?