• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Is this possable? C++ Help w/ pointers

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

KiKaL

Member
Joined
Jul 18, 2002
Alright, what im trying to get this to do is get a random number, then make the variable = that number. Is the best way to go at it the way I am? Or is there something else I could do? I appreciate any help.

code -

#include <iostream.h>
#include <time.h>
#include <stdlib.h>

int test;
int *p[] = {
int a = 1,
int a = 4,
int a = 8,
int a = 10,
int a = 13
};

main()
{
srand( ( NULL) );
test = rand() % 5;
cout << p[test];

return 0;
}
 
You can initialize an array with values. You can't do what you listed. In general, you can't declare any variables in an expression.

Code:
#include <iostream.h>
#include <time.h>
#include <stdlib.h>

int test;
int p[] = {1, 4, 8, 10, 13};

main()
{
	srand( ( NULL) );
	test = rand() % 5;
	cout << p[test];
	
	return 0;
}
 
Back