J
J. Campbell
I'm trying to make a class that represents a deck of cards and a
dealer for use in a card game. I'm fairly novice. The code compiles
(Dev c++(gcc 3.3.1)) without complaint, however it acts strange when I
run it. (In windows), when I double-click or run the prog from the
IDE, it displays the deck, then exits. When I run it from a console
window, if I type the filename eg "cards.exe", it displays the cards
as expected but doesn't pause at the end of the program. However if
I type "cards" without the explicit exe extension, the cards are not
displayed and I get the message:
"This application has requested the Runtime to terminate it in an
unusual way.
Please contact the application's support team for more information."
Any help is greatly appreciated. Joe
_________________________________________
#include <iostream>
#include <stdint.h>
#include <string>
using namespace std;
struct acard{
int suit;
int value;
uint32_t index; // to be used by shuffle function
};
class deck{
private:
string theSuits; // contains suits in order
string theValues; // contains values in order
acard* card; // an array of cards
int numcards;
public:
deck();
~deck();
void show();
// void shuffle();
};
deck::deck():
theSuits("\x05\x04\x03\x06") //c, d, h, s
,theValues("23456789TJKQA")
,numcards(theSuits.length() * theValues.length())
,card(new acard[numcards])
{
int cardnum(0);
for(int i = 0; i < theSuits.length(); ++i){
for(int j = 0; j < (theValues.length()); ++j){
cardnum = ((i * theValues.length()) + j);
card[cardnum].suit = i;
card[cardnum].value = j;
}
}
}
deck::~deck(){
delete [] card;
}
void deck::show(){
for (int i=0; i < numcards; ++i){
cout << theValues[card.value]
<< theSuits[card.suit] << endl;
}
}
int main()
{
deck mydeck;
mydeck.show();
system("pause");
return 0;
}
____________________________________
dealer for use in a card game. I'm fairly novice. The code compiles
(Dev c++(gcc 3.3.1)) without complaint, however it acts strange when I
run it. (In windows), when I double-click or run the prog from the
IDE, it displays the deck, then exits. When I run it from a console
window, if I type the filename eg "cards.exe", it displays the cards
as expected but doesn't pause at the end of the program. However if
I type "cards" without the explicit exe extension, the cards are not
displayed and I get the message:
"This application has requested the Runtime to terminate it in an
unusual way.
Please contact the application's support team for more information."
Any help is greatly appreciated. Joe
_________________________________________
#include <iostream>
#include <stdint.h>
#include <string>
using namespace std;
struct acard{
int suit;
int value;
uint32_t index; // to be used by shuffle function
};
class deck{
private:
string theSuits; // contains suits in order
string theValues; // contains values in order
acard* card; // an array of cards
int numcards;
public:
deck();
~deck();
void show();
// void shuffle();
};
deck::deck():
theSuits("\x05\x04\x03\x06") //c, d, h, s
,theValues("23456789TJKQA")
,numcards(theSuits.length() * theValues.length())
,card(new acard[numcards])
{
int cardnum(0);
for(int i = 0; i < theSuits.length(); ++i){
for(int j = 0; j < (theValues.length()); ++j){
cardnum = ((i * theValues.length()) + j);
card[cardnum].suit = i;
card[cardnum].value = j;
}
}
}
deck::~deck(){
delete [] card;
}
void deck::show(){
for (int i=0; i < numcards; ++i){
cout << theValues[card.value]
<< theSuits[card.suit] << endl;
}
}
int main()
{
deck mydeck;
mydeck.show();
system("pause");
return 0;
}
____________________________________