Home > Software engineering >  I had try to run a car game through c only
I had try to run a car game through c only

Time:05-11

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?

CodePudding user response:

You're defining your 'car' array as a 2d (1x1) 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.

  •  Tags:  
  • c
  • Related