please indent the code. it is too difficult to read this way.
Indent style - Wikipedia, the free encyclopedia
and try using structs.
I have this Code
It should cout minemap1 with 12345678910 no?with I jsut get strange letters...Code:void variables1(){ time_t t; time(&t); srand(t); int mine1 = rand() % 9 + 1; int mine2 = rand() % 9 + 1; int mine3 = rand() % 9 + 1; int mine4 = rand() % 9 + 1; int mine5 = rand() % 9 + 1; int mine6 = rand() % 9 + 1; int mine1x = rand() % 9 + 1; int mine2x = rand() % 9 + 1; int mine3x = rand() % 9 + 1; int mine4x = rand() % 9 + 1; int mine5x = rand() % 9 + 1; int mine6x = rand() % 9 + 1; int minemap1[ 10 ] = { 1,2,3,4,5,6,7,8,9,10 }; int* minema1 = &minemap1[10]; int minemap2[ 10 ] = { 'A','B','C','D','E','F','G','H','I','J' }; int minemap3[ 10 ] = { 'A','B','C','D','E','F','G','H','I','J' }; int minemap4[ 10 ] = { 'A','B','C','D','E','F','G','H','I','J' }; int minemap5[ 10 ] = { 'A','B','C','D','E','F','G','H','I','J' }; int minemap6[ 10 ] = { 'A','B','C','D','E','F','G','H','I','J' }; for ( int x = 0; x < 10; ++x){ cout << minemap1[x]; } cout << endl; for ( int y = 0; y < 10; ++y){ cout << minemap2[y]; } cout << endl; system("PAUSE"); } int main(){ cout << "-------------------------" << endl; cout << "| Welcome To MineSorter |" << endl; cout << "-------------------------" << endl; variables1 (); }
any help?
Last edited by alvaritos; 07-21-2011 at 10:07 AM.
please indent the code. it is too difficult to read this way.
Indent style - Wikipedia, the free encyclopedia
and try using structs.
I just don get the letters in the cout.. I get numbersCode:#include <ctime> #include <iostream> using namespace std; int main(){ int minemap2[ 10 ] = { 'A','B','C','D','E','F','G','H','I','J' }; for ( int y = 0; y < 10; ++y){ cout << minemap2[y]; } cout << endl; system("PAUSE"); }
OH well My fail mystake... It was "char" no " Int " xD
As if there is a proper indenting style...
it seems like u just copy and paste things u dont understand into 1 big project, and ask here what's wrong with them.
an array of 10 would start with [0] and end with [9].
Last edited by kibbles18; 07-21-2011 at 12:24 PM.
system("PAUSE");
^^ please please please dont use this
use cin.get();
Legen...wait for it...dary
ok and , why?
I will use that
using system("PAUSE") is like burning your furniture for heat when you have a perfectly good thermostat on the wall.
It's not portable. This works only on systems that have the PAUSE command at the system level, like DOS or Windows. But not Linux and most others...
It's a very expensive and resource heavy function call. It's like using a bulldozer to open your front door. It works, but the key is cleaner, easier, cheaper. What system() does is:
suspend your program
call the operating system
open an operating system shell (relaunches the O/S in a sub-process)
the O/S must now find the PAUSE command
allocate the memory to execute the command
execute the command and wait for a keystroke
deallocate the memory
exit the OS
resume your program
There are much cleaner ways included in the language itself that make all this unnessesary.
You must include a header you probably don't need: stdlib.h or cstdlib
It's a bad habit you'll have to break eventually anyway.
Instead, use the functions that are defined natively in C/C++ already. So what is it you're trying to do? Wait for a key to be pressed? Fine -- that's called input. So in C, use getchar() instead. In C++, how about cin.get()? All you have to do is press RETURN and your program continues.
Legen...wait for it...dary