Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int hand_amount;
- char cards;
- char card1;
- char card2;
- char card3;
- char card4;
- char card5;
- int final_hand;
- bool repeat = true;
- char y_n;
- int score;
- int cards_in_deck(char cards);
- int main()
- {
- while(repeat)
- {
- cout << "Enter how many card you have in your hand (Choose from 2 to 5 cards!):" << endl;
- cin >> hand_amount;
- final_hand = 0;
- if(hand_amount < 2 or hand_amount > 5)
- {
- cout << "Invalid number of cards chosen! Choose again." << endl;
- continue;
- }
- cout << "Now enter which cards you have in your hand:" << endl << "(The cards range from 2 to 9 - T, J, Q, K score 10 - A scores either 1 or 11 depending on the hand's score)" << endl;
- if(hand_amount == 2)
- {
- cout << "Card 1: ";
- cin >> card1;
- final_hand = final_hand + cards_in_deck(card1);
- cout << "Card 2: ";
- cin >> card2;
- final_hand = final_hand + cards_in_deck(card2);
- }
- else if(hand_amount == 3)
- {
- cout << "Card 1: ";
- cin >> cards;
- cout << "Card 2: ";
- cin >> cards;
- cout << "Card 3: ";
- cin >> cards;
- }
- else if(hand_amount == 4)
- {
- cout << "Card 1: ";
- cin >> cards;
- cout << "Card 2: ";
- cin >> cards;
- cout << "Card 3: ";
- cin >> cards;
- cout << "Card 4: ";
- cin >> cards;
- }
- else if(hand_amount == 5)
- {
- cout << "Card 1: ";
- cin >> cards;
- cout << "Card 2: ";
- cin >> cards;
- cout << "Card 3: ";
- cin >> cards;
- cout << "Card 4: ";
- cin >> cards;
- cout << "Card 5: ";
- cin >> cards;
- }
- if(final_hand > 21)
- {
- cout << "You're busted!" << endl;
- }
- else
- {
- cout << "Your final hand scores: " << final_hand << endl;
- }
- do
- {
- cout << "Do you want to try again? (y or Y for Yes , n or N for No)" << endl;
- cin >> y_n;
- switch(y_n)
- {
- case'y':
- case'Y':
- {
- repeat = true;
- break;
- }
- case'n':
- case'N':
- {
- repeat = false;
- break;
- }
- default:
- {
- break;
- }
- }
- }
- while(false);
- }
- return 0;
- }
- int cards_in_deck(char cards)
- {
- switch(cards)
- {
- case'2':
- {
- score = 2;
- }
- case'3':
- {
- score = 3;
- }
- case'4':
- {
- score = 4;
- }
- case'5':
- {
- score = 5;
- }
- case'6':
- {
- score = 6;
- }
- case'7':
- {
- score = 7;
- }
- case'8':
- {
- score = 8;
- }
- case'9':
- {
- score = 9;
- }
- case't':
- case'T':
- case'j':
- case'J':
- case'q':
- case'Q':
- case'k':
- case'K':
- {
- score = 10;
- }
- case'a':
- case'A':
- {
- if(final_hand > 21)
- {
- score = 1;
- }
- else
- {
- score = 11;
- }
- }
- }
- return score;
- }
Add Comment
Please, Sign In to add comment