I wrote the following program and it works for all cases except forany case that
ID: 3614146 • Letter: I
Question
I wrote the following program and it works for all cases except forany case that has two Aces come up first. Ex. 3 cards => A, A, T(ten) = 22 which isn't correct.... as both Aces need to then becomeones. However, after a couple more hours of coding (and severymessing up the once working code, which is what you see here) Istill couldn't get it. So this code is what I had be I startedmonkeying around.Please highlight your changes to in order make it easier for me tounderstand what you changed and wh for a lifesaver rating.
//Blackjack calc
#include <iostream>
using namespace std;
int main()
{
//varibles
char v, h;
int n, tot, c;
do
{
do
{
cout << "Enter number of cards in hand: "<< endl;
cin >> n;
} while (n>5 || n<2);
tot=0;
c=0;
do
{
cout << "Enter card values: " <<endl;
cin >> v;
switch (v)
{
case '2': tot= tot + 2;
//tot= tot+ 2;
break;
case '3':
tot= tot +3;
break;
case '4':
tot= tot +4;
break;
case '5':
tot= tot +5;
break;
case '6':
tot= tot +6;
break;
case '7':
tot= tot +7;
break;
case '8':
tot= tot +8;
break;
case '9':
tot= tot +9;
break;
case 't':
case 'T':
tot= tot +10;
break;
case 'j':
case 'J':
tot= tot +10;
break;
case 'Q':
case 'q': tot= tot + 10;
break;
case 'k':
case 'K':
tot= tot +10;
break;
case 'a':
case 'A':
tot= tot +11;
if( tot > 21)
{
tot= tot-10;
}
break;
default:
cout<< "don't fail at life" << endl;
break;
}
if (tot > 21)
{
cout << "You Busted" << endl;
}
if (tot == 21)
{
cout << "Blackjack! Winner Winner ChickenDinner!" << endl;
}
cout << tot << endl;
c++;
} while(c<n);
cout << "Play another hand (y/n): " << endl;
cin >> h;
} while ( h=='y' || h=='Y');
return 0;
}