Number Generator

Hey, how might I go about creating a number generator?
-Output a number value when I delete/pop an item from a queue
-The number MUST be 0, 10, 20, 30, or 40

I was originally going to use something like
srand((unsigned)time(0));
	string mystring= "BGRY";
	int n = mystring.length();
	const int m = 10;
	char output[m + 1];
	for (int i=0; i<m; i++)
	{
		output[i] = mystring[ rand() % n ];
	}
	output[m] = '\0';


But I forgot that I need to add up these numerical values, so the above obviously wouldn't work.
I don't quite see how the code relates to the question.
Unless there's more to the task, you can just drop cout << 0 << endl; in the pop member function and be done with it.
(rand()%5) * 10;
Another approach could be to choose a random index and read from an array of valid values. (like in your code)
The code isn't related to the question, it's just showing that that code outputs a string, which I cant use because I need actual numbers to add up.

ne555, couldn't that exceed 40 though?
It would make a range from 0-4, then multiply it by 10. So no, it wouldn't go above 40.
Oh awesome I got it working, thanks a lot. Now I need to figure out why my queues are filling up with random numbers when I delete a number from them. Well... I'm sure it's not random, my loops are probably goofed up.
Topic archived. No new replies allowed.