I am a beginner and I am not fully understanding what I am doing wrong using ctime and variables assigned random numbers. My newCard variable keeps returning the same value each time I call it. Any feedback would be appreciated!
This program is review of loops and cannot include user defined functions
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast<unsigned>(time(0)));
int total = 0;
int card1 = rand() % 10 + 1;
int newCard = rand() % 10 +1;
char deal, replay;
do
{
cout << " First Cards: " << card1 << ", " << newCard;
total = card1 + newCard;
cout << "\n Total: " << total;
cout << "\n Do you want another card? (Y/N) ";
cin >> deal;
while(deal == 'y' || deal == 'Y')
{
cout << "\n New Card = " << newCard;
total += newCard;
cout << "\n Total: " << total;
if(total == 21)
{
cout << "\n Congratulations!! BLACKJACK! ";
cout << "\n Would you like to play again? (Y/N):";
cin >> replay;
break;
}
else if(total > 21)
{
cout << "\n BUST ";
cout << "\n Would you like to play again? (Y/N):";
cin >> replay;
break;
}
cout << "\n Would you like another card? (Y/N): ";
cin >> deal;
}
while (deal == 'n' || deal == 'N')
{
cout << "\n Would you like to play again? (Y/N): ";
cin >> replay;
}
}
while(replay == 'y' || replay == 'Y');
while (replay =='n' || replay == 'N')
{
cout << "\n Exiting BlackJack \n\n";
return 0;
}
}