-
Bit O' Help Please
I am just trying to draw a simple card to dos console.. I am following this tutorial.. and for some reason, this small program is yielding over 102 compilation errors... compiler doesn't seem to like the #define's but they are written just like the tutorial.
Code:
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<windows.h>
using namespace std;
#define WHITE BACKGROUND_RED | \
BACKGROUND_GREEN | \
BACKGROUND_BLUE | \
BACKGROUND_INTENSITY
#define RED FOREGROUND_RED | FOREGROUND_INTENSITY
#define BLACK 0
typedef struct card
{
unsigned int face_value;
char suit;
card *next;
card(){next=NULL;}
}*mycard;
int main(void)
{
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
card new_card = new card;
srand(GetTickCount());
new_card->face_value = static_cast<unsigned>rand()%9+2;
new_card->suit = static_cast<char>rand()%4+3;
SetConsoleTextAttribute(hOut, new_card->suit<2?WHITE|RED:WHITE|BLACK);
cout << new_card->face_value << new_card->suit << " \n"
<< " \n"
<< " " << new_card->suit << " \n"
<< " \n"
<< " " << new_card->suit << new_card->face_value;
return 0;
}
-
You should not have any spaces after the backslash.
Probably should write like:
Code:
#define WHITE (BACKGROUND_RED | \
BACKGROUND_GREEN | \
BACKGROUND_BLUE | \
BACKGROUND_INTENSITY)
#define RED (FOREGROUND_RED | FOREGROUND_INTENSITY)
#define BLACK 0
I'm not sure if it is legal to use
typedef struct name {}*;
But then if it works, it works.
I think it should be:
card* new_card = new card;
Though maybe your typedef takes care of that, if it works.
Also, your casts arent written correctly.
For example:
static_cast<unsigned>(rand()%9+2)
not
static_cast<unsigned>rand()%9+2
-
Awesome help from the c++ witch ;)
Code:
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<windows.h>
using namespace std;
#define WHITE BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|BACKGROUND_INTENSITY
#define RED FOREGROUND_RED|FOREGROUND_INTENSITY
#define BLACK 0
typedef struct card
{
unsigned int face_value;
char suit;
card *next;
card(){next=NULL;}
}*mycard;
int main(void)
{
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
mycard new_card = new card;
srand(GetTickCount());
new_card->face_value = static_cast<unsigned>(rand()%9+2);
new_card->suit = static_cast<char>(rand()%4+3);
SetConsoleTextAttribute(hOut, new_card->suit<5?WHITE|RED:WHITE|BLACK);
cout << new_card->face_value << new_card->suit << " \n"
<< " \n"
<< " " << new_card->suit << " \n"
<< " \n"
<< " " << new_card->suit << new_card->face_value;
return 0;
}
Although I couldn't figure out why the #defines where whacked.. I just put everything on a single line. Compile and run.. you'll get a descent looking playing card :)
-
Hi,
You have a space problem in your first #define. And, when I run it, the white background of the card extends all the way to the right of the console window.
It's still pretty neat. :)
-
The board keeps adding that space in my first #define (the typed version looks ok before I post, but after I post the board adds the space for some reason)
Here is what I get when I run the program. Spacing problems will occur right now when the face value is a double digit but I can handle that as a seperate case: