ok, i've set x = 1, instead of randomating it... so the word is "Hello", Obviously 6 letters long...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 = 1; //(rand()%high_index)+low_index; //gets the length of the string for the while loop string::size_type word_length = wd[x].length(); // is 1, should be 6 //begins to set subs[] to each letter of wd cout<<"wd[x] == "<<wd[x]<<","<<"\n"<<"Length = "<<x<<"\n"<<"\n"; while (low_index < word_length) { subs[low_index] = wd[x].substr(low_index, low_index-1); cout<<"subs"<<low_index<<" == "<<subs[low_index]<<"\n"<<"\n"; 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(); }
BUT its returning 1, and I need to fix it badly



LinkBack URL
About LinkBacks


