ok
i got the program to output face cards, and gave them values for when i put them in.
my program crashes if i put in letters(face cards) when it asks what cards i have, it also doesnt continue in the beginning if it outputs a facecard. i still dont get how i would change the ace from 1 to 11 if needed. i was thinking
Code:
if(total>=22 && number=1)
{
total=n1+n2+n3+n4+n5 -10 //i can change totals as i go, but subtract 10
}
Code:
#include<iostream>
#include <cstdlib> //to use rand function
#include <ctime> // to use time as the seed for rand
using namespace std;
/*
Randall Foor
Blackjack program
9/30/10
*/
int main(){
for(int x=10;x>0;x--)
{
int number, cardnum;
int k,q,j,a;
int n1,n2,n3,n4,n5;
int total;
char anothercard,repeat,face;
srand(time(0));
for (int n=2; n>0; n--) //outputs random numbers for cards
{
number = 1 + rand() % 13;
if(number=1)
{
a=11;
cout<<" A "<<endl;
}
if(number== 11)
{
j=10;
cout<<" J "<<endl;
cin>>face;
}
if(number==12)
{
q=10;
cout<<" Q "<<endl;
cin>>face;
}
if(number==13)
{
k=10;
cout<<" K "<<endl;
cin>>face;
}
if(number>=2 && number<=9)
{
cout <<number<<endl;
}
}
cout<<"how many cards do you have? \n"; //asks how many cards you got
cin>>cardnum;
cout<<"what is the card value? \n"; //asks what the number of the card was
cin>>n1>>n2; //stores card value
total=n1+n2; //computes total
if(total==21)
{
cout<<"you win!! \n";
}
if(total>=22)
{
cout<<"busted \n";
}
if(total<=20)
{
cout<<"your total is "<<total<<" \n";
cout<<"would you like another card? <Y or N>:";
cin>>anothercard;
if(anothercard=='y' || anothercard=='Y') //if you want another card
{
for(int nextcard=3; nextcard>0;nextcard++) //enters loop to get card number
{
number = 1 + rand() % 13; //makes random number for card
cout <<nextcard<<" cards \n";
cout<<" next card value: ";
if(number== 11)
{
j=10;
cout<<" J \n";
}
if(number==12)
{
q=10;
cout<<"Q \n";
}
if(number==13)
{
k=10;
cout<<"K \n";
}
if(number>=2 && number<=9)
{
cout <<number<<endl;
}
cout<<"what was the card value? ";
if(nextcard==3)
{
cin>>n3;
total=n1+n2+n3;
cout<<"total value of cards "<<total<<endl;
if(total==21)
{
cout<<"you win!!! \n";
}
if(total>=22)
{
cout<<"busted \n";
}
}
if(nextcard==4)
{
cin>>n4;
total=n1+n2+n3+n4;
cout<<"total value of cards "<<total<<endl;
if(total==21)
{
cout<<"you win!!! \n";
}
if(total>=22)
{
cout<<"busted \n";
}
}
if(nextcard==5)
{
cin>>n5;
total=n1+n2+n3+n4+n5;
cout<<"total value of cards "<<total<<endl;
if(total==21)
{
cout<<"you win!!! \n";
}
if(total>=22)
{
cout<<"busted \n";
}
}
if(nextcard==5 || total>=21)
{
break; //breaks loop after
cout<<"you lose \n";
}
}
}
}
cout<<"Do you want to repeat? <Y or N> \n";
cin>>repeat;
if(repeat=='y' || repeat=='Y')
{ //breaks loop
system("cls");
}
if(repeat=='n' || repeat=='N'){ //breaks loop
system("cls");
break;
}
}
system("pause");
return 0;
}