Click here to Skip to main content
15,890,527 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWill do this generate a memory leak? Pin
Joan M30-Dec-06 23:17
professionalJoan M30-Dec-06 23:17 
AnswerRe: Will do this generate a memory leak? Pin
Gary R. Wheeler31-Dec-06 1:22
Gary R. Wheeler31-Dec-06 1:22 
AnswerRe: Will do this generate a memory leak? Pin
Gary R. Wheeler31-Dec-06 1:25
Gary R. Wheeler31-Dec-06 1:25 
AnswerRe: Will do this generate a memory leak? Pin
toxcct31-Dec-06 2:15
toxcct31-Dec-06 2:15 
AnswerYes, if the caller doesn't delete the pointer. Pin
CPallini31-Dec-06 6:58
mveCPallini31-Dec-06 6:58 
Questionno_input comes into reality Pin
davvid30-Dec-06 23:15
davvid30-Dec-06 23:15 
Answerjust a guess Pin
toxcct31-Dec-06 2:27
toxcct31-Dec-06 2:27 
GeneralRe: just a guess Pin
davvid31-Dec-06 2:46
davvid31-Dec-06 2:46 
Thanks.. I wrote different ways.. pls help me out !

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

struct
{
   char face;
    unsigned int value;
} 
card[13] = 
{    {'2', 2},{'2', 3},{'2', 4},
    {'5', 5},{'6', 6},{'7', 7},
    {'8', 8},{'9', 9},{'10', 10},
    {'J', 10},{'Q', 10},{'K', 10},
    {'A', 1}
};

int main()
{

    cout<<"simple twenty one card"<<endl;
    cout<<"------------------------"<<endl;
    int compcard=3,compscore=0,urscore=0,draw=0,urcard=0;
    char cond;
    const int high=21;
    //int ur;
    do
    {
        int comptotal=0,urtotal=0;
        //srand(time(NULL));
        srand((unsigned)time(0));
        cout<<"how many cards u want?(up to 5 cards)"<<endl;
        cin>>urcard;
    if (urcard>5)
    cout<<"You could not get more than five cards!"<<endl;
    else
    {
        cout<<endl<<"Ur cards..."<<endl;
        for (int ucard=0;ucard<urcard;ucard++)
        {
            int x = rand() % 13;
            printf(" |%c| ", card[x].face);
            
            urtotal+=card[x].value;
            if(urtotal>42)
            {
                urtotal=urtotal-30;
            }
            else if(urtotal>31&&urtotal<42)
            {
                urtotal=urtotal-20;
            }
            else if(urtotal>21&&urtotal<32)
            {
                urtotal=urtotal-10;
            }
            
        }

        cout<<endl;
        cout<<"My cards..."<<endl;
        for (int Ccard=0;Ccard<compcard;Ccard++)
        {
            int x = rand() % 13;
            printf(" |%c| ", card[x].face);
            comptotal+=card[x].value;
            
            if(comptotal>42)
            {
                comptotal=comptotal-30;
            }
            else if(comptotal>31&&comptotal<42)
            {
                comptotal=comptotal-20;
            }
            else if(comptotal>21&&comptotal<32)
            {
                comptotal=comptotal-10;
            }
            
        }
        cout<<endl;
        cout<<"I have "<<comptotal<<" and you have "<<urtotal<<" so ";

        if(comptotal<=high&& urtotal<comptotal)
        {
            cout <<"I win "<<endl;
            compscore++;
        }
        else if(comptotal<=high&& urtotal>high)
        {
            cout <<"I win "<<endl;
            compscore++;
        }
        else if (urtotal<=high&& urtotal>comptotal)
        {cout<<" you win"<<endl;
        urscore++;
        }
        else if (urtotal<=high&& comptotal>high)
        {cout<<" you win"<<endl;
        urscore++;
        }
        else //(comptotal==urtotal)
        {cout<<"no win"<<endl;
        draw++;
        }
    }
        cout<<"wana play again(n/y?)"<<endl;
        cin>>cond;
    }while(cond=='y');
        cout<<"I win   : "<<compscore<<endl;
        cout<<"you win : "<<urscore<<endl;
        cout<<"we draw : "<<draw<<endl;
        cout<<endl;
        //cin>>ur;

        
}

AnswerRe: no_input comes into reality Pin
CPallini31-Dec-06 11:02
mveCPallini31-Dec-06 11:02 
QuestionIE7 settings Pin
Waldermort30-Dec-06 20:52
Waldermort30-Dec-06 20:52 
AnswerRe: IE7 settings Pin
Michael Dunn30-Dec-06 21:50
sitebuilderMichael Dunn30-Dec-06 21:50 
QuestionHow do I have a &quot;Splitter Functionality&quot; without using CSplitterWind ? [modified] Pin
erajsri30-Dec-06 18:32
erajsri30-Dec-06 18:32 
AnswerRe: How do I have a &quot;Splitter Functionality&quot; without using CSplitterWind ? Pin
Mark Salsbery31-Dec-06 5:43
Mark Salsbery31-Dec-06 5:43 
GeneralRe: How do I have a &amp;quot;Splitter Functionality&amp;quot; without using CSplitterWind ? Pin
erajsri31-Dec-06 15:36
erajsri31-Dec-06 15:36 
AnswerRe: How do I have a &quot;Splitter Functionality&quot; without using CSplitterWind ? Pin
Cristian Amarie2-Jan-07 4:03
Cristian Amarie2-Jan-07 4:03 
Questionunary minus in backwards for-loop question [modified] Pin
FocusedWolf30-Dec-06 17:00
FocusedWolf30-Dec-06 17:00 
AnswerRe: unary minus in backwards for-loop question Pin
Michael Dunn30-Dec-06 18:16
sitebuilderMichael Dunn30-Dec-06 18:16 
AnswerRe: unary minus in backwards for-loop question Pin
John M. Drescher30-Dec-06 18:17
John M. Drescher30-Dec-06 18:17 
GeneralRe: unary minus in backwards for-loop question Pin
FocusedWolf30-Dec-06 19:07
FocusedWolf30-Dec-06 19:07 
QuestionHow to get a dialog size by ID? Pin
hanlei000000000930-Dec-06 16:01
hanlei000000000930-Dec-06 16:01 
AnswerRe: How to get a dialog size by ID? Pin
hanlei000000000930-Dec-06 16:14
hanlei000000000930-Dec-06 16:14 
AnswerRe: How to get a dialog size by ID? Pin
prasad_som1-Jan-07 17:24
prasad_som1-Jan-07 17:24 
QuestionNeed some help working with JPEGs... Pin
CoffeeAddict1930-Dec-06 12:06
CoffeeAddict1930-Dec-06 12:06 
AnswerRe: Need some help working with JPEGs... Pin
Joe Woodbury30-Dec-06 15:03
professionalJoe Woodbury30-Dec-06 15:03 
AnswerRe: Need some help working with JPEGs... Pin
Hamid_RT31-Dec-06 5:49
Hamid_RT31-Dec-06 5:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.