I'm trying to have the program out put either a color or a number at random.
Any help would be greatly appreciated.
Thank You in advance for not being evil.
I originally wasn't using a function so I created one and that didn't help. I also tried changing i from 0 to one. I thought a simple for loop would be easy
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int rand_num = rand();
int rand_color = rand() % 6; // should output color
int rand_distance = rand() % 5; // should output distance
int srand(time(NULL)); // initialize random seed
const string color[6] = { "red", "blue", "green", "orange", "yellow", "brown" };
const int distance[5] = { 7,25,20,10,15 };
void random_function()
{
if (rand_num % 2)
{
cout << color[rand_color];
}
else
cout << distance[rand_distance];
}
int main()
{
for (int i = 1; i < 30; i++)
{
random_function();
}
return 0;
}