Question on Functions with a For Statement

I have this code below and am new to functions. So if I were to do something like this:

double myFunction(double randomizer, double selection);
{
//what do I return here if I want 12 things printed from my for statement?
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

for(int i=1; i<=12; i++) //12 iterations starting from 1
{
  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 iterations
}
If all you are doing is displaying, you don't need to return anything.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
double void myFunction(double randomizer, double selection)
{
   for(int i=1; i<=12; i++) //12 iterations starting from 1
   {
        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 iterations
   }
}
Last edited on
oh duh. thanks!
Topic archived. No new replies allowed.