The problem is that sometimes when I run my program, sometimes it works, perfectly, then during the game, it just stops, and I can't do anything else.. (No errors/crashing etc..)
Sometimes it just appears empty, and nothing happens...
I am not sure why, can someone help me with this im confused, it should work
- reposted codeCode:#include <cstdlib> #include <iostream> using namespace std; int main () { int players_lives = 50; int players_points = 0; bool me = true; int q_n = 1; int q_right = 0; int q_wrong = 0; while (me) { string wd[50]; string h[50]; h[1] = "A common greeting"; h[2] = "Another word for requirement"; h[3] = "The end of life"; h[4] = "To raise your voice"; h[5] = "Something square that you keep things in"; h[6] = "None"; h[7] = "Over time this happens"; h[8] = "None"; h[9] = "A living thing"; h[10] = "None"; h[11] = "Does not cost anything"; h[12] = "Green and wavy"; h[13] = "Another word for bottle"; h[14] = "A small insect"; h[15] = "A metal substance"; h[16] = "Top level of your field"; h[17] = "Often white, and poofy"; h[18] = "Always the right thing to tell"; h[19] = "None"; h[20] = "An archers weapon"; h[21] = "Another word for immediately"; h[22] = "A place for pigs"; h[23] = "Thy"; h[24] = "A human emotion"; h[25] = "Large, green, brown, & woody"; wd[1] = "hello"; wd[2] = "need"; wd[3] = "death"; wd[4] = "yell"; wd[5] = "box"; wd[6] = "annoy"; wd[7] = "grow"; wd[8] = "flat"; wd[9] = "organ"; wd[10] = "fair"; wd[11] = "free"; wd[12] = "grass"; wd[13] = "flask"; wd[14] = "fly"; wd[15] = "led"; wd[16] = "elite"; wd[17] = "fluff"; wd[18] = "truth"; wd[19] = "all"; wd[20] = "bow"; wd[21] = "now"; wd[22] = "sty"; wd[23] = "you"; wd[24] = "love"; wd[25] = "tree"; string subs[50]; int low_index = 1; int high_index = 25; int lsub_index = low_index; int hsub_index = high_index; bool can_use[50]; int x; int i; bool cont = true; for (int t = 0; t < 50; t++) { can_use[t] = true; } 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-1 < word_length) { subs[low_index] = wd[x][low_index-1]; low_index++; } //loops so all characters are used and not overlap while (cont == true) { i = (rand()%word_length+1)+0; if (can_use[i] == true) { scrambledword = scrambledword + subs[i]; can_use[i] = false; } string::size_type new_word_length = scrambledword.length(); if (new_word_length == word_length && scrambledword != wd[x]) { cont = false; } } //for (int keep_top = 0; keep_top < 25; keep_top++) //clears the screen, and shows below at the top //{ //if (keep_top == 10) //{ cout<<"Question ["<<q_n<<"]"<<"\n"<<"\n"; cout<<"Lives ["<<players_lives<<"]"<<"\n"; cout<<"Questions right ["<<q_right<<"]"<<"\n"; cout<<"Questions wrong ["<<q_wrong<<"]"<<"\n"<<"\n"; cout<<"Word to unscramble is "<<scrambledword<<", Good luck "<<"\n"<<"\n"; cout<<"Hint - "<<h[x]<<"\n"; //cout<<"\n"; //} getline(cin, players_word); //for (int clear_screen = 0; clear_screen < 25; clear_screen++)//clears screen and shows below at the top //{ //if (clear_screen == 4) //{ if (players_word == wd[x]) { players_points = players_points + 1; cout<<"\n"<<players_word<<" is correct, +1 Point, current points: ["<<players_points<<"]"<<"\n"<<"\n"; cout<<"Press enter to continue"<<"\n"; q_right = q_right+1; } else { cout<<"\n"<<players_word<<" is incorrect, current points: ["<<players_points<<"]"<<"\n"<<"\n"; cout<<"Press enter to continue"<<"\n"; players_lives = players_lives -1; q_wrong = q_wrong+1; } q_n = q_n + 1; //} //cout<<"\n"; //} if (players_lives <= 0) { players_lives = 0; cout<<"You have lost!"<<"\n"; cout<<"Press enter to exit"<<"\n"; me = false; } cin.get(); } }



LinkBack URL
About LinkBacks



