Jump to content

  • Log In with Google      Sign In   
  • Create Account


Youbar

Member Since 12 Oct 2012
Offline Last Active Dec 07 2012 10:36 PM
-----

Posts I've Made

In Topic: (C++) Printing Out 2d Array

07 December 2012 - 03:53 PM

How would those lines work?
map[(y * 5) + x] = ...
seems like y is pointing to 5, which would just slow things down by the looks of it.
And:
for (int i=0; i<25; ++i) std::cout << i[*map] << " \n"[i%5];
How does i[*map] work?
i points to map?

In Topic: (C++) Printing Out 2d Array

06 December 2012 - 09:38 PM

Thanks. 1+ rep for you again. :)

In Topic: (C++) Printing Out 2d Array

06 December 2012 - 09:20 PM

Oh, I understand now, thanks. Posted Image

EDIT:
I'm getting an error in this code:

#include <iostream>
using namespace std;
int map[5][5] =
{
1, 1, 3, 1, 1,
1, 0, 0, 0, 1,
1, 0, 2, 0, 1,
1, 0, 0, 0, 1,
1, 1, 1, 1, 1
};
int column = 0;
int row = 0;
int x = 2;
int y = 2;
char dir = 'x';
bool game_ended = false;
void stop()
{
cout << endl;
system("PAUSE");
}
void cls()
{
system("CLS");
}
void print_map()
{
for (row = 0; row < 5; ++row)
{
  for (column = 0; column < 5; ++column)
  {
   cout << map[row][column] << ' ';
  }
  cout << endl;
}
}
void redraw()
{
cls();
print_map();
}
int main()
{
print_map();
cout << "What direction would you like to go in?" << endl;
cin >> dir;
while (game_ended != true)
{
  if (dir == 'w')
  {
   map[x][y] = 0;
   x--;
   map[x][y] = 2;
   redraw();
  }
}
stop();
}

I get an error that says:

Unhandled exception at 0x00411ced in Turn-based RPG.exe: 0xC0000005: Access violation writing location 0x0041aff4.

I am guessing this is due to the array. How would I fix this?

In Topic: (C++) Printing Out 2d Array

06 December 2012 - 08:41 PM

What I mean, is how does that print out all of the array? It looks as if it would just print out the array like this:
1
0
2
0
1

In Topic: (C++) Printing Out 2d Array

06 December 2012 - 06:49 PM

By the looks of it, the code would print the array diagonally.
Can you please explain how that loop would work?

PARTNERS