1. ## A few questions

Hi the first question is, how can I set a min and max for the rand function. At the moment i'm seeding from ctime then using
Code:
`int theNumber = rand() % max + 1`
It picks a number between 0 and 100 then if its too high it sets the max integer to the number just guessed. How can I change the min one.

My second question is:

Code:
```#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
string input;
const int MAX_ITEMS = 10;
int inventoryCount = 0;
string inventory[MAX_ITEMS];
vector<string> shopList;
int shopListCount = 0;
shopList.push_back("Sword") && (shopListCount++);
shopList.push_back("Shield" && (shopListCount++);
shopList.push_back("Firewood") && (shopListCount++);

cout << "Welcome to Ben's Test RPG, input inventory if you want to see what you own, type quit to leave aand type shop to see the shop" << endl;

do
{
cin >> input;

if(input == "inventory")

if(inventoryCount != 0)

for (int i=0; i < inventoryCount; i++)

cout << inventory[i];

else

cout << "Sorry you have no items." << endl;

if(input == "shop")

for (int j=0; j < shopListCount; j++)

cout << shopList[j];

if(input == "quit")
;

else

cout << "Sorry incorrect choice.";

}while(input != "quit")

}```
How can I make it so it adds to my shopListCount when the vector gets pushed back.

Thanks,
Ben

2. Originally Posted by Chipmunkey
It picks a number between 0 and 100 then if its too high it sets the max integer to the number just guessed. How can I change the min one.
Imagine you could generate a random number between 0 and 50. Now add 50 to this number. You now have a random number between 50 and 100. Make sense?

3. how can I set a min and max for the rand function
Read Prelude's article on Using rand().

It picks a number between 0 and 100 then if its too high it sets the max integer to the number just guessed.
Your code snippet produces a number between 1 and max inclusive.

How can I make it so it adds to my shopListCount when the vector gets pushed back.
Just increment:
Code:
```shopList.push_back("Sword");
++shopListCount;
shopList.push_back("Shield");
++shopListCount;
shopList.push_back("Firewood");
++shopListCount;```
Of course, since you are manually inserting 3 items, you might as well initialize shopListCount to 3.

4. Why do you need shopListCount at all? Just use shopList.size().

5. Code:
`shopList.push_back("Shield") && (shopListCount++);`

6. Finally... A practical use for high school algebra.

Well we know that rand() % num gives us a number from 0 to (num - 1). So after a few revisions and tests in my head, here's my final answer:
(rand() % (max - (min - 1))) + min

If min = 50 & max = 100 then:

(rand() % (100 - (50 - 1))) + 50
=(rand() % (100 - 49)) + 50
=(rand() % 51) + 50
=(0...50) + 50
=(50...100)