how do I get the substring of a variable?
im trying to make a "Trivia" game...
with scrambling words lol...
this is my code so far...
Code:
#include <iostream>
using namespace std;
int main ()
{
string wd[50];
cout<<"Trivia will begin"<<"\n"<<"\n";
wd[1] = "hello";
wd[2] = "need";
wd[3] = "help";
wd[4] = "yell";
wd[5] = "box";
string subs[50];
int low_index = 1;
int high_index = 5;
int lsub_index = low_index;
int hsub_index = high_index;
bool subs_has_set[50];
int x; int i;
bool cont;
string players_word;
string scrambledword;
//makes a random number, to select the word we will use
srand((unsigned)time(0));
x = (rand()%high_index)+low_index;
//gets the length of the string for the while loop
string::size_type word_length = wd[x].length();
//begins to set subs[] to each letter of wd
while (low_index < word_length+1)
{
subs[low_index] = wd[low_index];
low_index++;
}
//loops so all characters are used and not overlap
while (cont == true)
{
i = (rand()%word_length)+low_index;
if (subs_has_set[i] == false)
{
scrambledword = scrambledword + subs[i];
subs_has_set[i] == true;
}
string::size_type new_word_length = scrambledword.length();
if (new_word_length == word_length)
{
cont == false;
}
}
cout<<"Word to unscramble is "<<scrambledword<<", Good luck "<<"\n";
getline(cin, players_word);
cin.get();
}
all I want is to get substring of wd, so I can get each letter and set it to subs[low_index] then put it back together randomly