why is this c++ program not working?

shiftyape

Honorable
Feb 23, 2013
48
0
10,580
0
fist of al, dont critisize me for being unoriginal, stupid, or lame. the error im getting is:
<error reading characters of string>
<unable to read memory>





#include <iostream>
#include <cmath>
#include <Windows.h>
#include <ctime>
#include <cstdlib>
#include <conio.h>
#include <cstring>
using namespace std;



int main() {

char* space[39] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
" ", " ", " ", " ", " ", " ", " ", " ",
" ", " ", " ", " ", " ", " ",
" ", " ", " ", " ", " ",
" ", " ", " ", " ",
" ", " ", " ", " ",
" ", " "};

int a, b, c, d;

char key = ' ';
cout << "use wasd to move around" << endl;

Sleep(3000);



cout << endl; cout << endl; cout << endl; cout << endl; cout << endl; cout << endl; cout << endl; cout << endl; cout << endl; cout << endl;

a = 38;
b = 39;
c = 35;
d = 34;

while (1) {
system("cls");
cout << space[a] << "/\\" << endl; //38
cout << space << "/ \\" << endl; //39
cout << space << "| |" << endl; //39
cout << space << "| |" << endl; //39
cout << space[a] << "/ \\" << endl; //38
cout << space[c] << "--- ---" << endl; //35
cout << space[d] << "/ \\" << endl; //34
cout << space[d] << "----- ----" << endl; //34
cout << space << "| |" << endl; //39
cout << space << "/ \\" << endl; //39
cout << space << "-------" << endl; //39


char left = 'a';
char right = 'd';
char down = 's';
char up = 'w';

key = _getch();

if (key == left)
{
a = a - 1;
b = b - 1;
c = c - 1;
d = d - 1;
}
else if (key == right)
{
a = a + 1;
b = b + 1;
c = c + 1;
d = d + 1;
}
}

system("PAUSE");
return 0;
}


// i know i suck at writing code just try and help anyway

 

ddpruitt

Honorable
Jun 4, 2012
227
0
10,860
7
First you shouldn't be asking for homework help here.
Second the compiler it would help if you explained what it's suppose to do. I've found in most cases that errors result when people don't understand what it is that they need the code to do.

Your code has a number of different issues, your naming isn't consistent, your indentation isn't consistent, and your structure is a disaster. You shouldn't use system to clear the screen or pause, there are portable solutions to this. You need to clean up the code first and the error should become clear. To be fair I see several problems that would be resolved through cleaner data structures and simpler code.
 

ddpruitt

Honorable
Jun 4, 2012
227
0
10,860
7
First you shouldn't be asking for homework help here.
Second the compiler it would help if you explained what it's suppose to do. I've found in most cases that errors result when people don't understand what it is that they need the code to do.

Your code has a number of different issues, your naming isn't consistent, your indentation isn't consistent, and your structure is a disaster. You shouldn't use system to clear the screen or pause, there are portable solutions to this. You need to clean up the code first and the error should become clear. To be fair I see several problems that would be resolved through cleaner data structures and simpler code.
 

ddpruitt

Honorable
Jun 4, 2012
227
0
10,860
7


This is why I advised restructuring the code, there's a much bigger problem with the "array". In fact I would be surprised if the code compiles without several pages worth of warnings.
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580
0


this isnt a homework assignment, its just something i made in my spare time for fun. thanks for answering though. i will try and fix that stuff. sorry, i just started a programming class a couple weeks ago with no experience before that, so thats why my structure sucks. thanks for the help

didnt know about that portable stuff, but now that ive researched it, ive found cin.get(); to be better. thanks.
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580
0


its not, dont worry
 

shiftyape

Honorable
Feb 23, 2013
48
0
10,580
0


super helpful, thanks. do i just extend it to 40 then?
 
Thread starter Similar threads Forum Replies Date
L Apps General Discussion 1
ssmana Apps General Discussion 6
Lumia925 Apps General Discussion 4
A Apps General Discussion 3
M Apps General Discussion 1
UItmaWepn Apps General Discussion 0
S Apps General Discussion 9
S Apps General Discussion 2
D Apps General Discussion 1
P Apps General Discussion 3
viveknayyar007 Apps General Discussion 0
shiftyape Apps General Discussion 18
C Apps General Discussion 3
shiftyape Apps General Discussion 1
R Apps General Discussion 9
j_a_k_e_24 Apps General Discussion 1
John_VanKirk Apps General Discussion 5
R Apps General Discussion 1
fdd2blk Apps General Discussion 3
C Apps General Discussion 1

ASK THE COMMUNITY

TRENDING THREADS