Hello nlizzy,
Lines 25 and 26 will do no good down there. They should be inside "main" before the call to "srand". The "const" is OK and could be used.
Lines 13 - 16 will most likely generate compile errors as written. Line 13 you are trying to create an array of strings with a size of zero. this is not allowed. It must be a size greater than zero. In this case it should be 4 because there are 4 elements that you are initializing the array with. What you are trying to do here is take an array of strings with a size of zero and put 4 strings into it.
Line 18 starts out OK, but then you say to take an element of "wordList" using the "rand" as the subscript, which is OK. But where have you defined "wordList" and what should it contain?
Based on what you started with I rearranged your program to something that might work for you:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include<iostream>
#include<cstdlib>
#include<ctime>
#include <string>
//#include <vector> // <--- Needed if you are going to use a vector.
//using namespace std; // <--- Best not to use.
int main()
{
//const int NUM_SHIRT = 4;
//vector<string> shirtColor(NUM_SHIRT);
std::string guess;
std::string shirtList[4]{ "blue", "red", "green", "yellow" }; // <--- Changed.
std::string faceList[2]{ "glasses", "no glasses" }; // <--- Changed.
std::string eyeList[3]{ "blue", "brown", "green" }; // <--- Changed.
std::string hairList[4]{ "red", "black", "brown", "blonde" }; // <--- Changed.
srand(time(0));
guess += shirtList[rand() % 4] + ", ";
guess += faceList[rand() % 2] + ", ";
// <--- Other arrays here.
std::cout << guess << std::endl;
return 0;
}
|
In lines 15 - 18 from C++11 on the "=" is not needed just the {}s. The same is true for numeric variables and "chars". An empty set of {}s will initialize a variable to zero in the form that is needed. Also it is better to start the variable name with a lower case letter and save the capital letters for "classes" and "structs".
You could also write line 15 as:
std::string shirtList[NUM_SHIRT]{ "blue", "red", "green", "yellow" };
although I would change the name of the variable.
See if this does something of what you are looking for.
Hope that helps,
Andy