void & for

Posts 1–11 of 11 · Page 1 of 1
void & for
I have this Code
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 ();
	}
It should cout minemap1 with 12345678910 no?with I jsut get strange letters...

any help?
Code:
#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");
	}
I just don get the letters in the cout.. I get numbers

OH well My fail mystake... It was "char" no " Int " xD
When indenting, try to line up brackets that belong together.
As if there is a proper indenting style...
Quote Originally Posted by Fovea View Post
As if there is a proper indenting style...
there is a style I like. and because of that it is the bestest
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].
system("PAUSE");

^^ please please please dont use this

use cin.get();
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.
Quote Originally Posted by FailHacker View Post
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.
Those analogies were epic.
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us