samedi 30 janvier 2021

Is there a way to print the sum of randomly generated numbers in a do while loop? C++

I am writing a program to very fundamentally simulate a black jack game using rand() % 11. We have to tell the players their running total as well as asking if they want another card (hit). My first problem is getting multiple random numbers and my second problem is not being able to add the two random numbers together. Strings are not allowed. Here's the block of code that I think is causing there's errors. I am very new to c++. Do I need to have multiple variables with the rand() %10 +1 to add them? I know that the add + add won't work but I can't figure out an alternative.

int add = rand() % 10 + 1;                                                  
bool hit = false;                                                           
int i = 0;                                                                  
       
do{                                                                                     
cout << "Players 1 running total is " << add;                                          
i++;                                                                        
cout << " \n ";                                                             
cout << "Would you like another number? (0-yes or 1-no) ";                  
cin >> hit;                                                             
if(hit == 0){                                                           
cout << " You got an " << add << " \n ";                            
cout << "You're running total is " << add + add;                                       
}                                                                       
                                                                                   
} while (hit == false); 



Aucun commentaire:

Enregistrer un commentaire