How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Ingo U Your Own Question
Ingo U
Ingo U, Software Engineer
Category: Homework
Satisfied Customers: 755
Experience:  Over 25 years experience in software development. Expert in Microsoft .Net, C#, C++, VB, SQL
Type Your Homework Question Here...
Ingo U is online now
A new question is answered every 9 seconds

Write a C++ program to simulate the card game 21 for a single

This answer was rated:

Write a C++ program to simulate the card game 21 for a single player against the computer. Deal 2 cards to the computer, but only show one, and 2 cards face up to the player. Ask the player if he would like an extra card and deal one each time he answers y. If he answers n or busts (card total is greater than 21). If he busts thank the player for playing and ask if he would like to play again. If he doesn't, the computer then shows it's second card and proceeds to hit until it reaches 17 or busts. If it is a tie, both players lose. There are 52 cards in a deck, face cards should be replaced by 10's, and Aces replaced by 11's unless they would cause a bust, then they become 1's. If there is more than one ace in the hand only one at a time becomes a one. No card may be chosen twice, after an index is selected and it's value is stored, the index element should be changed to -1 before the next card is drawn. If -1 is drawn it should be ignored and another card should be drawn. If neither the player nor the computer busts, the person whose card total is closer to 21 wins. The computer should then ask if the player wants to play again and repeat the game if the player answers y and thank the player and exit if the player answers no. Please do not use bool, and keep all functions in the same file. I am using the code::blocks compiler. Comments would also be greatly appreciated as I am just learning. Also, please name a fair price. I would make an offer, but I don't know what fair is and don't want to insult you. Thank you for reading this.
is there a deadline for this? I should be able to help.
Customer: replied 3 years ago.

Thank you, XXXXX XXXXX deadline is 11:59 PM October 7.

OK. That should be doable. As for the pay, we are not supposed to negotiate price in this category (programming). You can always decide on a bonus after you rate my service.
Customer: replied 3 years ago.

I didn't know it would tell me ahead of time how much was expected. I said October 7th, but I meant October 8th. Thank you!

Even better!
Have you used references in C++ before, e.g. to pass arguments to functions?
Customer: replied 3 years ago.

I don't understand them, but yes we have gone over them in class. We haven't covered strings yet.

Can you upload any code samples, e.g. previous homeworks, labs, etc used in class so I can gauge the level of class? Use a file sharing site like wikisend.
Ingo U

PS If you're not familiar with wikisend, it's easy and free:
Go to and upload the file there (no need to sign up). You will then get a page that has the File ID and Download Link. Copy either the File ID or the Download Link and come back here and paste it in your reply.

Customer: replied 3 years ago.

No, unfortunately, the professor is very low tech and doesn't give us any files to work with. We had to write a couple of programs, but the only one I can find is my latest. pay Final.exe The class website is and the last day of class is Wednesday so as far as the notes go is as much as can be used. Simpler is better. Ideally, I'd like to be able to read and understand your program as a reference for helping me write my own.

Here you go:

Please let me know if you need anything changed or explained.
Ingo U
were you able to use the code I provided? If not, please let me know and I'll whatever I can to correct it or help. If so, please don't forget to rate my answer, otherwise I don't get paid.
Ingo U
Customer: replied 3 years ago.

Thank you for getting the code done so quickly. Sorry for my poor communication. I sleep during the day, have evening classes and work a full-time graveyard shift. I haven't had a chance to look this over very well yet, but I promise you I will and will rate you. The only problem with the way the program runs is that there are face cards and aces rather than being purely numerical. All of the other faults are simply that I'm a complete beginner, and can't discern an array from an argument. I may be able to figure it out, but it would be great if you could spell it out for me. Like I said, I haven't really haven't had the chance to look it over well yet, and should be asleep for another 5 hours. Also, I noticed the switch statement, but don't quite understand it's purpose, why there are cases without instructions or breaks, and it's the first time I've seen a switch without a default. My best guess to the default is that none is needed, becauses the cases are being pulled from the deck, and it isn't possible for anything other than any of those cases to be selected. Thanks in advance. -Jared

Thanks -
I interpreted the issue with the face cards to mean how many points they should count for, which is just like in the real game. It would take a little trickery dealing with the aces differently, but I could do it. I think the game is more realistic - in fact it is exactly how blackjack is played in a casino - the way it is. Perhaps you can get clarification from the instructor on this.

A switch statement is just a more readable way than writing a long chain of if-then-else statements.
The switch statement can be written like that when there is the same action to be taken for multiple cases. Think of it as saying "if the card is 2 or 3 or 4 or 5...etc then take the following action....".

And yes you're right, since the switch covers every every possible card with a corresponding case statement, a default action would never be executed.
Customer: replied 3 years ago.

I'm sorry for not being clearer when I said to replace the face cards with 10's. You're right, a casino wouldn't substitute 10's for face cards. Yes, I'm sure that he didn't want face cards, and you're right, that doesn't make any sense since face cards make it more realistic, and like suits, don't affect game play. It also doesn't make sense that he specified that in the case of a tie, both players lose, but that is an easy fix. I still haven't been to sleep yet, but now that I look at it again, it is all much clearer. Your comments are very helpful. Sorry for the inconvenience of asking you to replace the face cards with 10's. I can see how it completely changes the way the ace is treated.


You need to spend $3 to view this post. Add Funds to your account and buy credits.
Ingo U and other Homework Specialists are ready to help you
Customer: replied 3 years ago.

It looks and works great! Thanks for all your help!