Erollisi Marr - The Nameless

Go Back   Erollisi Marr - The Nameless > NON EQ Stuff (Real life, other games, etc.) > Small Talk


Reply
 
Add/Share Add/Share Thread Tools Display Modes
Old 05-19-2004, 07:50 AM   #1
Baidieneriy
Registered User
 
Join Date: Nov 2002
Posts: 364
Default ONE freaking error...C++ related

//Matt Maurer
//Black Jack


#include<iostream.h>
#include<string.h>
#include<stdlib.h>
#include<iomanip.h>
#include<conio.h>



void main()
{
int option2 = 0;
char rule;
char player1 ;
char player1name [15];
char player2;
char player2name [15];
int playernum = 0;
int option = 0;

{
cout<<"Welcome To..."<<endl;
cout<<"\nBBBBBBBBBB LL AAAAAAAAA CCCCCCCCCCC K K ";
cout<<"\nB B LL A A C K K ";
cout<<"\nB B LL A A C K K ";
cout<<"\nB B LL A A C K K ";
cout<<"\nBBBBBBBBBB LL A A C KKK ";
cout<<"\nB B LL AAAAAAAAA C K K ";
cout<<"\nB B LL A A C K K ";
cout<<"\nB B LL A A C K K ";
cout<<"\nBBBBBBBBBB LLLLLLLLLLLL A A CCCCCCCCCCC K K ";
cout<<"\n";
cout<<"\n JJJJJJJJJJJJ AAAAAAAAAA CCCCCCCCCCC K K ";
cout<<"\n JJ A A C K K ";
cout<<"\n JJ A A C K K ";
cout<<"\n JJ A A C K K ";
cout<<"\n JJ AAAAAAAAAA C KKK ";
cout<<"\n JJ A A C K K ";
cout<<"\nJJ JJ A A C K K ";
cout<<"\nJJ JJ A A C K K ";
cout<<"\nJJJJJJJJ A A CCCCCCCCCCC K K ";
cout<<endl;


}
cout << "Hello and Welcome to Matt's Black Jack Table, best of luck to ya! \n";endl;
cout << "One or Two players? " ;
cin >> playernum;

if (playernum !=1 || playernum !=2)
{
cout << "I'm sorry, there is not enough room at this table for more than 2 players.\n"; endl;
cout << "What'll it be pal, 1 or 2 players? "; endl;
cin >> playernum;
}

else
{
switch (playernum);
}


switch (playernum)
{

case 1:
cout << "Player One, what is your name? \n"; endl;
cin.ignore(80, '\n');
cin.get(player1name, 15);
cin.ignore(80, '\n');
clrscr();
cout << "Welcome, " << player1name <<endl;
break;

case 2:
cout << "Player One, what is your name? ";endl;
cin.ignore(80, '\n');
cin.get(player1name, 15);
cin.ignore(80, '\n');
clrscr();
cout << "Welcome to my table, " << player1name << ". \n"; endl;
cout << "Player Two, what is your name? ";endl;
cin.get(player2name, 15);
cout << "So nice of you to join us, " << player2name << ". \n"; endl;
clrscr();
break;


}

cout << "Before we begin, do you wish to see the rules? \n"; endl;
cout << "Enter 1 for yes or 2 for no: \n";endl;
cin >> option;


switch (option)
{
case 1:
cout<<"Here are the rules:"<<endl;
cout<<"A natural 21 means an automatic win."<<endl;
cout<<"If both players hand's are equal, then it's a tie."<<endl;
cout<<"The game is played with a standard 52 card deck. "<<endl;
cout<<"The deck re-shuffles after 52 cards have been dealt."<<endl;
cout<<"There is no doubling down or other complications."<<endl;
cout<<"J,Q,K all count as 10. An Ace can count as an 11 or a 1."<<endl;
cout<<endl;
cout << "Press 1 to begin the game. \n" << endl;
cin >> option2;

switch (option2)
{
case 1:
cout << "Ok, let's begin the game. " <<endl;
}
break;




case 2:
cout << "Ok, let's begin this game." <<endl;

break;
}

typedef int bool;
const int false=0;
const int true=1;
const int decksize=52;
const int maxhand=5;
struct card {
char value;
char suit;
bool used;
};

card dealerhand[maxhand];
card userhand[maxhand];

int totalu=0, totald=0;
bool bu=false, bd=false, gameover=false;

void dealerplay(card deckd[]);
void userplay(card decku[]);
void handhit(card hand[], int &cd, int &total);

int game ()
{
srand(time(0));
char choice=' ';
do
{
totalu=0;
totald=0;
bu=false;
bd=false;
gameover=false;
card deck[decksize];
for (int i=0; i<decksize; i++)
{
deck[i].used=false;
if ((i>=0) && (i<=12))
deck[i].suit='s';
else if ((i>=13) && (i<=25))
deck[i].suit='d';
else if ((i>=26) && (i<=38))
deck[i].suit='c';
else if ((i>=39) && (i<=51))
deck[i].suit='h';
if (i==0)
{
for (int a=0; a<=7; a++)
deck[a].value=(a+48)+2;
deck[i+8].value='t';
deck[i+9].value='j';
deck[i+10].value='q';
deck[i+11].value='k';
deck[i+12].value='a';
}
if (i==13)
{
for (int x=13; x<=20; x++)
deck[x].value=(x+48)-11;
deck[i+8].value='t';
deck[i+9].value='j';
deck[i+10].value='q';
deck[i+11].value='k';
deck[i+12].value='a';
}
if (i==26)
{
for (int z=26; z<=33; z++)
deck[z].value=(z+48)-24;
deck[i+8].value='t';
deck[i+9].value='j';
deck[i+10].value='q';
deck[i+11].value='k';
deck[i+12].value='a';
}
if (i==39)
{
for (int c=39; c<=51; c++)
deck[c].value=(c+48)-37;
deck[i+8].value='t';
deck[i+9].value='j';
deck[i+10].value='q';
deck[i+11].value='k';
deck[i+12].value='a';
}
}

//Print out the deck
//for (int p=0; p<decksize; p++)
//cout<<"\""<<deck[p].value<<"\""<<deck[p].suit<<endl;

dealerplay(deck);
userplay(deck);

if(bu==false && gameover==false)
{
cout<<"The dealer totaled "<<totald<<" and ";
if(bd==false && totald>=totalu)
cout<<"won!"<<endl;
else if(bd==true)
cout<<"busted! YOU WIN!!!"<<endl;
else if(bd==false && totald<=totalu)
cout<<"lost! YOU WIN!!!"<<endl;
}
else if(bu==true && gameover==false)
cout<<"The dealer won."<<endl;

cout<<endl<<endl;
cout<<"Would you like to play again? Type y for yes or anything else for no."<<endl;
cin>>choice;
cout<<endl<<endl<<"_-=+++=-_ _-=+++=-_ _-=+++=-_ _-=+++=-_"<<endl<<endl;
}while(choice=='y');

return 0;
}
//--------------------------------------------------------------------------------------------
void dealerplay(card deckd[])
{
int rcard2=0, cdd=0;
//Fill the dealer's hand (5 cards)
for(int v=0; v<=4; v++)
{
do
{
rcard2=rand()%52+1;
}while(deckd[rcard2].used==1);
deckd[rcard2].used=1;
dealerhand[v].value=deckd[rcard2].value;
dealerhand[v].suit=deckd[rcard2].suit;
}
for(int haha=0; haha<=1; haha++)
{
switch(dealerhand[haha].value)
{
case '2':totald+=2;break;
case '3':totald+=3;break;
case '4':totald+=4;break;
case '5':totald+=5;break;
case '6':totald+=6;break;
case '7':totald+=7;break;
case '8':totald+=8;break;
case '9':totald+=9;break;
case 't':totald+=10;break;
case 'j':totald+=10;break;
case 'q':totald+=10;break;
case 'k':totald+=10;break;
case 'a':totald+=11;break;
default:cout<<"Not a real card.\n";break;
}
}
cdd+=2;
cout<<"The dealer is showing a "<<dealerhand[0].value<<" of "<<dealerhand[0].suit<<"."<<endl;

while(totald<17)
handhit(dealerhand, cdd, totald);

if(totald>21)
bd=true;


//Print out all parameters of one random card
/*cout<<"\n\n-------------------------------\n\n";
cout<<deckd[rcard2].value<<" "<<deckd[rcard2].suit<<" "<<deckd[rcard2].used;
cout<<"\n\n-------------------------------\n\n";*/
return;
}
//----------------------------------------------------------------------------------------------
void userplay(card decku[])
{
int rcard3=0, cdu=0;
char hsu=' ';
//Fill the user's hand (5 cards)
for(int o=0; o<=4; o++)
{
do
{
rcard3=rand()%52+1;
}while(decku[rcard3].used==1);
decku[rcard3].used=1;
userhand[o].value=decku[rcard3].value;
userhand[o].suit=decku[rcard3].suit;
}
cdu+=2;
for(int haLA=0; haLA<=1; haLA++)
{
switch(userhand[haLA].value)
{
case '2':totalu+=2;break;
case '3':totalu+=3;break;
case '4':totalu+=4;break;
case '5':totalu+=5;break;
case '6':totalu+=6;break;
case '7':totalu+=7;break;
case '8':totalu+=8;break;
case '9':totalu+=9;break;
case 't':totalu+=10;break;
case 'j':totalu+=10;break;
case 'q':totalu+=10;break;
case 'k':totalu+=10;break;
case 'a':totalu+=11;break;
default:cout<<"Not a real card.\n";break;
}
}
cout<<endl;
for(int lad=0; lad<=1; lad++)
cout<<"Your "<<(lad+1)<<" card is a "<<userhand[lad].value<<" of "<<userhand[lad].suit<<"."<<endl;
if((userhand[0].value=='a' && userhand[1].value=='j') || (userhand[0].value=='j' && userhand[1].value=='a'))
{
gameover=true;
cout<<"You got Blackjack! Congratulations, you win!"<<endl;
cout<<"Total: "<<totalu<<endl;
return;
}
cout<<"Total: "<<totalu<<endl;
do
{
cout<<"Would you like to hit (h) or stay (s)?"<<endl;
cin>>hsu;
if(hsu=='h')
{
handhit(userhand, cdu, totalu);
cout<<"Your "<<cdu<<" card is a "<<userhand[cdu].value<<" of "<<userhand[cdu].suit<<"."<<endl
<<"Total: "<<totalu<<endl;
if(totalu>21)
{
bu=true;
cout<<"You busted."<<endl;
}
}
else if(hsu=='s')
break;
else
{
cout<<"Invalid input. Please enter an h or an s."<<endl;
continue;
}
}while(cdu<=3 && bu==false);
if(cdu==5 && bu==false)
{
gameover=true;
cout<<"Son of a gun! You got a five card charlie! You win!"<<endl;
}
cout<<"Total: "<<totalu<<endl;
return;
}
//----------------------------------------------------------------------------------------------
void handhit(card hand[], int &cd, int &total)
{
switch(hand[(cd+1)].value)
{
case '2':total+=2;break;
case '3':total+=3;break;
case '4':total+=4;break;
case '5':total+=5;break;
case '6':total+=6;break;
case '7':total+=7;break;
case '8':total+=8;break;
case '9':total+=9;break;
case 't':total+=10;break;
case 'j':total+=10;break;
case 'q':total+=10;break;
case 'k':total+=10;break;
case 'a':total+=11;break;
default:cout<<"Not a real card.\n";break;
}
cd++;
return;
};
}


what is wrong!?
__________________
Baidieneriy 1.0
Baidieneriy is offline   Reply With Quote
Old 05-19-2004, 12:46 PM   #2
Reddoak
Registered User
 
Join Date: Nov 2002
Posts: 428
It's been a really long time since I used C++ last, but I think from what I'm
seeing is that you've included braces ( { & } ) in unnecessary spots.

Have you tried compiling this program? And if so, what error messages is it
giving?
__________________
Reddoak Whispershot - Retired from all things EQ

WoW:
-----------------
Nanaki
60 Tauren Shaman
<For Sale By Owner>
Skywall Server
Reddoak is offline   Reply With Quote
Old 05-19-2004, 07:12 PM   #3
Baidieneriy
Registered User
 
Join Date: Nov 2002
Posts: 364
Whenever I compile it I get a declaration syntax error.
__________________
Baidieneriy 1.0
Baidieneriy is offline   Reply With Quote
Old 05-20-2004, 02:54 AM   #4
Ndiin
Registered User
 
Join Date: Feb 2003
Posts: 14
I hate to say it, but you've got a lot more than one error there. I spent about an hour debugging and there's still a lot more work to be done.

Here are a few of the problems I found:

- Your code is difficult to read because it is not organized very well. Put prototypes at the top of your code before main. Likewise define your struct card before main. Add comments! Even if you don't intend to have others read your code, they'll help you in the future when you come back to it.

- Do not attempt to recreate typedef bool, it is already part of c++. Instead of making true, false, maxhand, and decksize consts, simply #define them at the very beginning, before main. ie.
#define TRUE 1
#define FALSE 0
etc
You do not need a ; after each #define.

- You never closed main. Figure out where it is supposed to close, and add a }. I'm not sure if it was intentional, but your game() code should not be inside main. Close main before you code game().

- Main is always declared as an int. Add a return at the end.

- clrscr does not appear to be in any of the standard libraries you have included. Simply create your own.
void clrscr () {
int i = 0;
while ( i < 80 ) {
cout << endl;
i++;
}
}

- add " using namespace std; " to the top of your code, right below your includes.

- conio.h does not appear to be a valid header, though perhaps this is simply in my version of c++

- If you're programming in C++, you should include C++ headers. This means you should have:
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>

- cout << "foo"; endl; is wrong. It should be cout << "foo" << endl; You were inconsistant and used both, so you need to go back to the beginning and fix all of these errors.

- if ( playernum != 1 || playernum != 2 ) will always be true. Try playernum != 1 && playernum != 2. Also, I recommend using a while loop here.
while (playernum != 1 && playernum != 2 ) {
cout << "blah blah balh" << endl;
cin >> playernum;
}

- After the previous code segment, you have switch(playernum) twice. Delete one of them.

- In your switch ( option ), at the end of case one where you ask the user to input 1 to begin, you do not need another switch statement.

- Some of the errors I received trying to compile could have simply been due to a different version of C++ I have installed, so some of my comments may not apply.

This is as far as I've gotten in the debugging process. Aside from this, my advice is to simply look at the warnings the compiler gives you and figure out what's wrong. Oh, and make sure you use proper indentation. I can't really tell what yours looks like because of the lack of spacing when you paste it into a post, but you should have been able to tell that main wasn't closed.

Good luck!

Edit: Oh, one last thing. Whenever you post your code and ask for advice, it's always a good idea to include the exact error message you get.
Ndiin is offline   Reply With Quote
Old 05-22-2004, 12:45 PM   #5
gojirra monk
Registered User
 
Join Date: Nov 2002
Posts: 304
I gave up on C++ the first time I saw cout being leftshifted 'hello world' times.
gojirra monk is offline   Reply With Quote
Old 05-24-2004, 12:37 PM   #6
Vidden
Banned User
 
Join Date: Dec 2002
Location: Texas - DFW Area
Posts: 1,253
conio.h is valid. I do think that there are a few extra brackets like they said above me.

And also, you really need to add comment lines in there. It is hard to see what is going on where.
Vidden is offline   Reply With Quote
Old 05-24-2004, 09:59 PM   #7
Ndiin
Registered User
 
Join Date: Feb 2003
Posts: 14
ah, just looked it up and conio.h is a windows library, and I program in linux. That explains my confusion.
Ndiin is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 05:30 PM.


Powered by: vBulletin. Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.