Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I had try to run a car game through c++ only

As mentioned in the title I try to run a car game developed using only CPP but faced problems in line 20 of my code…

#include<conio.h>
#include<dos.h> 
#include <windows.h>
#include <time.h>

#define SCREEN_WIDTH 90
#define SCREEN_HEIGHT 26
#define WIN_WIDTH 70 

using namespace std; 

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
COORD CursorPosition;

int enemyY[3];
int enemyX[3];
int enemyFlag[3];
char car[1][1] = {{' ',' '},
               {'*','*','*'}};//<--------------------here
int carPos = WIN_WIDTH/2;
int score = 0; 

void gotoxy(int x, int y){
 CursorPosition.X = x;
 CursorPosition.Y = y;
 SetConsoleCursorPosition(console, CursorPosition);
}
void setcursor(bool visible, DWORD size) {
 if(size == 0)
     size = 20;  
 
 CONSOLE_CURSOR_INFO lpCursor;   
 lpCursor.bVisible = visible;
 lpCursor.dwSize = size;
 SetConsoleCursorInfo(console,&lpCursor);
}

in my code error is poping as
<>

will anybody help me to find an error in my code?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’re defining your ‘car’ array as a 2d (1×1) array, which would need to be initialized like:

char car[1][1] = {{' '}}; // probably not useful (it only holds 1 char)

You probably need to change the size of your array. Something like:

char car[2][3] = {     // here car is 2x3, an array of size 2 
    { ' ', ' ', ' ' }, // each element is an array of size 3
    { '*', '*', '*' }
}

In the future, it will be helpful if you also post the error that you’re getting.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading