Code:#include <iostream> #include <vector> #include <cstdlib> #include <ctime> #include <fstream> using namespace std; struct soldier { soldier(void); int agility; int tech; int gunskill; }; soldier :: soldier(void) { agility = rand() % 31 + 10; tech = rand() % 31 + 10; gunskill = rand() % 31 + 10; } struct mforce { mforce(void); int w; int z; vector<soldier> millitant; }; mforce :: mforce(void) { w = rand() % 1001 + 1; z = rand() % 1001 + 1; x = rand() % (w + 1) + z; } int main() { mforce batt[10]; srand(time(0)); printf("%d",sizeof(batt[2].millitant;) / sizeof(int)); system("pause"); return 0; }
First, I defined what a soldier is. What I wanted to do was define what a soldier was, than create a structure, mforce (for Militant force) that would generate a random number of millitants. I went to a C++ forum, and somebody told me how to to do this: use a vector. The guy included it in the code, but he didn't tell me how the heck to use a vector. Help would be appreciated. If you look towards the end, what I'm trying to do is see how many millitants are in battalion 2. Add and delete code as you want if it'll help me understand what I'm aim to do. Thanks guys.
EDIT: Also, I want each battalion to generate a random number of millitants. I have somewhat a clue on how to do this, but as I stated above, things get confusing because of the Vector.