Text RPG - Damage function (Random within range)

To try and further my knowledge with C++, I am currently working on a text RPG. Currently, I am working on a damage function which chooses a random integer within a range, defined by minimum and maximum variables. I've done a bit of searching, and have come across a few things, but most of it has been over my head, or I've had difficulty implementing it with min and max variables.

Any help or knowledge is gretaly appreciated, Thanks.
1
2
3
4
5
6
7
8
9
int random(int limit)
{
  return rand()%limit;
}

int random(int min,int max)
{
  return random(max-min+1)+min;
}
I am currently working on a text RPG.


*cough*cough*

http://www.cplusplus.com/forum/articles/28558/
Disch, you should count how many times you have linked to that article so far.
Thanks for your help guys. I would have searched a bit harder, but I was in school and in a hurry.

And thank you Disch. I thought the console would be the preferred choice for a text RPG, but I guess text-based games aren't that great at all.
Last edited on
Hi Disch, actually it is not really that bad for a person to do a text-based RPG. His objective is to learn more about C++. Rather than writing code snippet to test understanding, he opt to have a "project" as his objective.

Of cuz if his intention is to make and sell his "project" then we would say to do gaming, the initial choice is not a good medium but if it is just for learning C++, I feel having a text-based RPG is not a sin afterall :)
Topic archived. No new replies allowed.