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