I have this code and I want to be able to call it as a function. I looked up how, but am pretty confused and always get an error. Here is my code I want to make a function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
srand(time(0)); //seed the random number
for(int i=1; i<=12; i++ ) //12 iterations
{
randomizer = rand() % 2;
if (randomizer == 0)
{
selection += ( selection == 8 ) ? -0.5 : 0.5;
}
else
{
selection += ( selection == 0 ) ? 0.5 : -0.5;
}
cout << selection << endl; //print out the 12
}
#include <all that crap>
usingnamespace (however your using name space)
void randomiser () // you got to declare it in the global scope its called the //prototype and as it returns no value just a cout its void if it was addin //stuff it wud be return a+G
//am beginner too
int main () {
randomizer // call the function here and however you want to call it
}
after main you can have the code and how it works...you get the hang of it in a few days
void randomiser ()
{
srand(time(0)); //seed the random number
for(int i=1; i<=12; i++ ) //12 iterations
{
randomizer = rand() % 2;
if (randomizer == 0)
{
selection += ( selection == 8 ) ? -0.5 : 0.5;
}
else
{
selection += ( selection == 0 ) ? 0.5 : -0.5;
}
cout << selection << endl; //print out the 12
}
}