Thread: bool functions

  1. #1
    Registered User sentienttoaster's Avatar
    Join Date
    Nov 2002
    Posts
    79

    bool functions

    ok. I am having a problem with a function that calls a boolean. Here is my code. any comments appreciated!


    bool showcomp(char isgameover);

    void showcomphand(bool isgameover)
    {
    cout<<"My hand is: ";
    if(!isgameover)
    {
    cout<<hiddencard<<" "<<endl;
    }
    for( int i = !isgameover; comphand[i] !=0; i++)
    {
    switch (comphand[i])
    {
    case 1: cout<<"A ";
    break;
    case 11: cout<<"J ";
    break;
    case 12: cout<<"Q ";
    break;
    case 13: cout<<"K ";
    break;
    default: cout<<comphand[i]<<" "<<endl;
    break;
    }
    }
    cout<<endl;
    }
    This has been a public service announcement from GOD.

    111 1111

  2. #2
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    use code tags!
    what is the problem exactly?

    the if statement do look suspect tho..

    is isgameover an int?
    when last game is played does it really equal 0?

    didnt see rest of the code so just asking..
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  3. #3
    Registered User sentienttoaster's Avatar
    Join Date
    Nov 2002
    Posts
    79

    here is my code

    /*Epsilon Omega Gamma*/
    #ifndef _epsilonomegagamma_h
    #define _epsilonomegagamma_h



    void dealcomp(int number);
    void dealme(int number);
    bool showcomp(char isgameover);
    void showme();
    void blackjack();
    int randnumber();
    int randnumber1;
    void newround();
    bool compturn();
    bool myturn();
    short comphand[11];
    int comphandsize, comphandvalue, compace;
    int myhand[11], myhandsize, myhandvalue, myace, cardsleft;
    int i=0;
    char hiddencard;
    int start();
    int number;
    bool continuegame1;
    bool continuegame2;




    void blackjack()
    {
    cardsleft=52;
    hiddencard=2;
    for (i=0; i<11; i++)
    {
    comphand[i]=0;
    myhand[i]=0;
    }
    }
    int randnumber()
    {
    static bool card[52];
    if(cardsleft==52)
    {
    for(i=0; i<52; i++)
    {
    card[i]=1;
    }
    }
    randnumber1=rand()%52;
    while(!card[number])
    {
    randnumber1=rand()%52;
    }
    cardsleft--;
    card[number]=false;
    return (randnumber1%13)+1;
    }
    void newround()
    {
    bool continue1=true, continue2=true, over=false;
    compace=0, comphand[11]=0, myace=0, myhand[11]=0;
    for(i=0; i<11; i++)
    {
    comphand[i]=0;
    myhand[i]=0;
    }
    cardsleft=52;
    dealcomp(2);
    showcomp(false);
    dealme(2);
    showme();
    if(comphand[11]==21||myhand[11]==21)
    {
    continuegame1=false, continuegame2=false;
    }
    while((continuegame1||continuegame2) && comphand[11] < 22 && myhand[11] <22)
    {
    continuegame1=compturn();
    if(continuegame1||continuegame2)
    {
    continuegame2=myturn();
    }
    }
    cout<<endl;
    if(comphandvalue > 21 && myhandvalue > 21)
    {
    cout<<"We are both over."<<endl;
    }
    if(comphandvalue > 21 && myhandvalue <=21)
    {
    cout<<"I am over."<<endl;
    over=1;
    }
    if(myhandvalue > 21 && comphandvalue <=21)
    {
    cout<<"You are over."<<endl;
    over=1;
    }
    if(comphandvalue > myhandvalue && !over)
    {
    cout<<"I have "<<comphandvalue<<", which beats your "<<myhandvalue<<".";
    cout<<"You lose."<<endl;
    }
    if(myhandvalue > comphandvalue && !over)
    {
    cout<<"You have "<<myhandvalue<<", which beats my "<<comphandvalue<<".";
    cout<<"You win."<<endl;
    }
    if(myhandvalue == comphandvalue && !over)
    {
    cout<<"Tie. We both have "<<comphandvalue<<"."<<endl;
    }
    }
    void dealcomp(int number)
    {
    for( ; number; number--)
    {
    int newcard = randnumber();
    comphand[comphandsize] = newcard;
    comphandsize++;
    if(newcard == 1 && comphandvalue <=10)
    {
    compace++;
    comphandvalue +=11;
    }
    else if(newcard > 10)
    {
    comphandvalue +=10;
    }
    else
    {
    comphandvalue += newcard;
    }
    if(comphandvalue > 21 && compace)
    {
    compace--;
    comphandvalue -=10;
    }
    }
    }
    void dealme(int number)
    {
    for( ; number; number--)
    {
    int newcard=randnumber();
    myhandsize++;
    if(newcard == 1 && myhandvalue <=10)
    {
    myace++;
    myhandvalue +=11;
    }
    else if(newcard >10)
    {
    myhandvalue +=10;
    }
    else
    {
    myhandvalue +=newcard;
    }
    if(myhandvalue >21 && myace)
    {
    myace--;
    myhandvalue -=10;
    }
    }
    }
    bool compturn()
    {
    if(comphandvalue < 17 && compace || comphandvalue < 17)
    {
    cout<<"I will take a card."<<endl;
    dealcomp(1);
    showcomp(false);
    return true;
    }
    cout<<"I'm not taking a card."<<endl;
    return false;
    }
    bool myturn()
    {
    char addcard='Q';
    cout<<"Do you want a card? y = yes, n = no."<<endl;
    cin>>addcard;
    while(1)
    {
    switch(addcard)
    {
    case 'y':
    case 'Y': cout<<"You take a card: "<<endl;
    dealme(1);
    showme();
    return true;
    case 'n':
    case 'N': return false;
    default: cout<<endl<<"Huh? Do you want another card or not. y = yes, n = no."<<endl<<" >"<<endl;
    cin>>addcard;
    break;
    }
    }
    }
    void showcomphand(bool isgameover)
    {
    cout<<"My hand is: ";
    if(!isgameover)
    {
    cout<<hiddencard<<" "<<endl;
    }
    for( int i = !isgameover; comphand[i] !=0; i++)
    {
    switch (comphand[i])
    {
    case 1: cout<<"A ";
    break;
    case 11: cout<<"J ";
    break;
    case 12: cout<<"Q ";
    break;
    case 13: cout<<"K ";
    break;
    default: cout<<comphand[i]<<" "<<endl;
    break;
    }
    }
    cout<<endl;
    }
    void showme()
    {
    cout<<"Your hand: ";
    for( int i =0; myhand[i] !=0; i++)
    {
    switch (myhand[i])
    {
    case 1: cout<<"A ";
    break;
    case 11: cout<<" J ";
    break;
    case 12: cout<<"Q ";
    break;
    case 13: cout<<"K ";
    break;
    default: cout<<myhand[i]<<" "<<endl;
    break;
    }
    }
    cout<<endl;
    }
    int start()
    {
    srand(time(0));
    void mygame();
    char BJNewgame='q';
    cout<<"Blackjack. Wanna play? y = yes, n = no."<<endl<<">";
    cin>>BJNewgame;
    cout<<endl;
    while(BJNewgame !='n' && BJNewgame !='N')
    {
    switch(BJNewgame)
    {
    case 'y':
    case 'Y': start();
    break;
    case 'n':
    case 'N': break;
    default: cout<<endl<<"Huh? Do you wanna play Blackjack? y = yes, n = no"<<endl<<">";
    cin>>BJNewgame;
    break;
    }
    }
    cout<<"Have a nice day!"<<endl;
    return 0;
    }
    #endif
    This has been a public service announcement from GOD.

    111 1111

  4. #4
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    USE CODE TAGS!
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  5. #5
    Iamregistered
    Guest

    Re: bool functions

    Originally posted by sentienttoaster

    Code:
    //open code tag here!!!
    bool showcomp(char isgameover);
    
    void showcomphand(bool isgameover)
    {
    	cout<<"My hand is: ";
    	if(!isgameover)
    	{
    		cout<<hiddencard<<" "<<endl;
    	}
    	for( int i = !isgameover; comphand[i] !=0; i++)
    	{
    		switch (comphand[i])
    		{
    			case 1: cout<<"A ";
    				break;
    			case 11: cout<<"J ";
    				break;
    			case 12: cout<<"Q ";
    				break;
    			case 13: cout<<"K ";
    				break;
    			default: cout<<comphand[i]<<" "<<endl;
    				break;
    		}
    	}
    	cout<<endl;
    }
    //close code tag here!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Classes help
    By DarkAlex in forum C++ Programming
    Replies: 13
    Last Post: 01-26-2008, 03:00 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Using private class members in static functions
    By sethjackson in forum C++ Programming
    Replies: 2
    Last Post: 09-23-2005, 09:54 AM
  5. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM