All pastes #257269 Raw Edit

Something

public cpp v1 · immutable
#257269 ·published 2006-11-25 03:29 UTC
rendered paste body
#include <iostream>#include <cctype>using namespace std; int main (){    char card;    int number_of_cards, i, total, tmp,eleven;    total = 0;    cout << "This is a blackjack program.\n";    cout << "Type the number of cards you have in your hand (Should be between 2-5 cards).\n";    cin >> number_of_cards;    cout << "Enter 2-9 if you have that card. If you have a 10, type t.\n";    cout << "If you have a jack, type j. Queen, type q. King, type K.\n";    cout << "If you have an ace, type a if you'd like for it to be a one, A for eleven.\n";	eleven = 0;    for(i=0;i<number_of_cards;i++)    {         cin >> card;		card = toupper(card);		switch(card){			case 'A':				if(total > 10){ //change it to a 1					tmp = 1;				}else{					tmp = 11;					eleven++;				}			break;			case 'Q':				tmp = 10;			break;			case 'K':				tmp = 10;			break;			case 'J':				tmp = 10;			break;			case 'T':				tmp = 10;			break;			default :				if(bool(isdigit(card)) == true && card != 0 && card != 1){					tmp = card-48; //-48 to fix ascii offset				}else{					//User intered something stupid help correct this					i--;					cout << "You entered an invalid card please re-enter this card" << endl;					tmp = 0;				}			break;		}		cout << "Card is " << tmp << endl;        total = total + tmp;    }	if(total > 21){		//Ok time to use that eleven varaiable		if(eleven > 0){			//There were aces counted as 11			while(eleven != 0){				if(total <= 21){					break; //ok it reduced it below 21				}else{					//reduce total					total = total-10;					//remove the ace from the pool					eleven--;				}			}		}	}        cout << "Your hand score is " << total << " points.\n";              if (total < 21){     cout << "You don't exactly have 21, but you have a chance of winning this hand.\n";    }    else if (total == 21 ){        cout << "You win!\n";    }    else if (total > 21){        cout << "Sorry, but since you passed 21, you lose.\n";    }                    system("Pause.");    return 0;}