I have to write a program for my programming class. The assignment is thus:
Create a program that allows the user to type in cards in a dealer's hand, one at a time. If the user types in something that is not a valid card, notify them and do not include that input in the hand. Once they are done (either ask them how many cards they are entering or look for a special input such as a blank line, or a dash "-"), print out whether the dealer would stand or hit.
#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>
#include <algorithm>
usingnamespace std;
bool card_validity_check(string card) {
if ((card[0] == 'A' || (card[0] >= '2' && card[0] <= '9') || card[0] == '0' || card[0] == 'J' || card[0] == 'Q' || card[0] == 'K') && (card[1] == 'H' || card[1] == 'C' || card[1] == 'D' || card[1] == 'S')) {
returntrue;
} else {
returnfalse;
}
}
int hand_value(vector<string> cards) {
int total;
total = 0;
for (string card : cards) {
switch (card[0]) {
case'A':
if (total >= 17) {
total += 1;
}
elseif (total < 17) {
total += 11;
}
case'2':
case'3':
case'4':
case'5':
case'6':
case'7':
case'8':
case'9':
total += card[0] - '0';
case'0':
case'J':
case'Q':
case'K':
total += 10;
}
cout << total << endl;
}
return total;
}
bool stands(vector<string> hand){
return 0;
}
int main() {
vector<string> cards;
string card;
entry:
cout << "Enter a card for the dealer:" << endl;
cin >> card;
if (card_validity_check(card)) {
cout << "This is a valid card" << endl;
cards.push_back(card);
cout << hand_value << endl;
} else {
cout << "This is not a valid card. Please retry." << endl;
goto entry;
}
cin >> card;
}
I'm not entirely done with my program, but the program is currently supposed to, when you enter AH, output 11. In Visual Studio 2015, it outputs a string of letters and numbers. If anyone can point out my problem, that would be fantastic, thanks.