Sunday, August 2, 2009

C++ problem. array n=[2,4,6,8,10,29,11,12]; array o=[49,48,46,45,44]. need 2 select a random number 4rm both?

has to kinda look like a c++ code.


something like this:


#include%26lt;iostream%26gt;


#include%26lt;math.h%26gt;


#include%26lt;iomanip%26gt;


using namespace std;





int main()


{


int n=[2,4,6,8,10,29,11,12,13,14,15,16,18,19...


int o=[49,48,46,45,44,43,42,39,38,37,36,33,3...


d1=math.rand()*[n];


d2=math.rand()*[n];


d3=math.rand()*[o];





cout%26lt;%26lt;"1"%26lt;%26lt;"-"%26lt;%26lt;"2"%26lt;%26lt;"-"%26lt;%26lt;"3"%26lt;%26lt;endl;


cout%26lt;%26lt;d1%26lt;%26lt;"-"%26lt;%26lt;d2%26lt;%26lt;"-"%26lt;%26lt;d3%26lt;%26lt;endl;





return 0;


}


but i'm not sure it's right! :D

C++ problem. array n=[2,4,6,8,10,29,11,12]; array o=[49,48,46,45,44]. need 2 select a random number 4rm both?
//get # of elements


int sizeA = (sizeof n) / (sizeof n[0])


int sizeB = (sizeof o) / (sizeof o[0])





//A random integer in the valid range of array N


int random_integer = rand() % sizeA;





cout %26lt;%26lt; n[random_integer];





//A random integer in the valid range of array O


random_integer = rand() % sizeB;





cout %26lt;%26lt; o[random_integer];


No comments:

Post a Comment