So in my Computer Science class we had to write a basic game, so i wrote a simple blackjack program. My only issue is my teacher dislikes the use of "goto", and suggested bool loops. Can anyone help me with this? i have no idea what to do with bool loops or how to make one, and a google search offered no help
while(move == 1)
{
//put in all the code for hitting in here;
}
//Put in all the code for stay here
return 0;
}
If you want to improve this game a little bit, you might want to look at doing:
-A standard deck of cards has 12/52 cards which give a 10, make your code reflect this.
-If you are dealt 11 + 10, that is an instant win, called a blackjack (and you get big time riches at the casino)!
I'm sorry, I'm not sure what you mean. realize i have no idea what a bool loop is or anything. My teacher said "use one of these" then gave me no information on it.
Also for the 12/52, i was thinking of having another random number gen with another variable, probably "chance10". it generates a number between one and 52 and if its 1-12, ten will be added to cardSum. is there a more efficient way to do that or would that work?
I've never heard that term before, but all loops are basically boolean, meaning they run until a condition becomes either true or false.
Random numbers are not the best way to simulate a deck of cards. If you use a vector, all you need to do is call shuffle() then take the cards off the top just like a real deck.
So this is what i ended up with, just changed the "if" too "while" and deleted the second if. And it does still work, but the problem is the "goto" being there. for some unknown reason she doesnt like that there. so how would i make this code work without using goto?
There is a very very good reason for your teacher not wanting that goto statement to be there. Putting goto statements in code makes it very quickly unreadable and impossible to modify or maintain. You can get rid of that goto and just put the code asking the user what they want to do inside the while loop.
Everything after goto label; in your while loop can go outside and after the while loop.
Ask yourself this? Does the code need to execute more than once? If the answer is no, it should not be in a while loop.
Everything after goto label; in your while loop can go outside and after the while loop.
It IS outside of the while loop, even though his indentation may indicate otherwise.
@OP, take out all those calls to srand(). You only need to do it once. Line 10 is ok, but remove the rest of them.
Also, read about the do-while loop.