Simple randomizer

I am trying to take a number and give it a 50/50 chance of adding .5 or subtracting .5 without going negative or over 22. This is what I got but I am completely new and know its wrong but I can't find how to do it in the articles.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using namespace std;

int main ()
{
	srand(time(0));
	int your_number;

cout <<"Please enter a number" << endl;//prompt

cin >> your_number; //input

	for (int i = 1; i <= 22; i +- 0.5)
	{
		double r = rand()*22 / RAND_MAX;//between 0 and 22
		cout << r << endl;
	}

system("pause");

return 0;


}
You don't need the for loop and for the random, make it so it randomly generates either a 1 or 0, then check the number and make it add if it a 1 or take away if it a 0.

If you understand what I mean.
Topic archived. No new replies allowed.