#include <iostream>
#include <vector>
#include <ctime>
#include <string>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
string Alphabets[26] = { "Hey","How","Are","you","Doing","Today","My","Name",
"Is","John","Its","Great","to","finally","meet","you","today",
"wow","summer","was","long","school","has","started","now"};
string RandString[20];
srand(time(NULL));
for (int k = 0; k < 20; k++) {
int temp = rand() % 26;
RandString[k] = Alphabets[temp];
}
for (string RandomString : RandString ) {
cout << RandomString << endl;
}
for (int i = 20; i >= 0; i--) {
cout << RandString[i] << endl;
}
}
I'm having trouble understanding my code to an extent. Right now, my code is randomly generating 20 strings into an array. I have one range for loop that shows the strings that we're picked by the random string generator. But my issue comes with the last part of the code and that is to reverse it. I believe what I'm doing wrong is that I'm trying to reverse strings that haven't been randomly generated yet. Therefore, I believe that's why nothing appears, and if this is the case, I have forgotten how to take an array that's been fully populated and then assign it to a different variable which 'I think also has to be an array'. I know this is a silly question but could someone tell me why, if this array isn't being populated when called outside of the for loop why is the ranged for loop able to then print it out?