OMG it was all going well, until right now I don't know why all of a sudden when I run the game, it tells me COngratulations you've won when I have won, and at the same time it says BETTER LUCK NEXT TIME?????? What is wrong with this code? I have no idea why it's doing this, someone please help me!
please help me i appreciate it, this is the last time im postingCode:#include <iostream> #include <cstdlib> #include <fstream> #include <string> #include <cmath> using namespace std; void define_word(char d); int main() { char c, ch, ch1, ch2; char word[50]; char word1[25]; int length, i, next_guess, num_letters, m, x; do { do { cout<<"\n\n\n\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"; cout<<"\t******************* PrOgRaMmInG VoCaB GuEsSeR ********************\n"; cout<<"\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n\n\n"; cout<<"\n\t(S) Start the Game\n\n\t(Q) Quit\n\n\n\t Enter your choice: "; cin>> ch2; }while (ch2 != 's' && ch2 != 'S' && ch2 != 'Q' && ch2 != 'q'); if (ch2 == 'Q' || ch2=='q') exit (0); if (ch2 == 's' || ch2=='S') { ifstream fin("words.txt"); if (!fin) { cout<<"\n\nYou are missing a file called words.txt\n\n"; return 0; } for (i=0;!fin.eof();i++) fin.getline(word,25); fin.close(); do { x=rand(); }while(x>i || x<0); ifstream finn("words.txt"); for (i=0;!finn.eof();i++) { finn>>c; finn.getline(word,25); if (x==i) break; } finn.close(); } if (ch2 == 'S' || ch2=='s') { length=strlen(word); //Computes the length of the string char choosen[50]="\0"; num_letters=0; m=0; for (i=0; i<=24; i++) { if (word[i]=='\0') {word1[i]='\0'; break;} if (word[i]==' ') {word1[i]=' '; num_letters++;} if (word[i]!=' ') word1[i]='-'; } next_guess=length+2-num_letters; //Number of Guesses Left do { definition: define_word(c); if (m!=0) cout<<"\n\n\t\t\tChoosen letters : "<<choosen<<"\n"; cout<<"\n\n\n\t\t\t "<<word1; cout<<"\n\n\n\tYou have "<<next_guess<< " guesses left, choose a letter : "; cin>>ch; cin.get(); for (i=0;i<25;i++) if (choosen[i]==ch) { cout<<"You have choosen "<< ch <<" already!!\n"; goto definition; } next_guess--; choosen [m]=ch; choosen [m+1]=','; m+=2; for (i=0;i<=49;i++) if (word[i]==ch || word[i]==ch+32 || word[i]==ch-32) word1[i]=ch; if (!strcmpi (word1,word)) { cout<<"\n\t\t\t "<<strupr(word); cout<<"\n\n\t\t\tCongratulations, You have won!\n"; break; } }while(next_guess>0 || !strcmpi (word1,word)); if (strcmpi (word1,word)) { cout<<"\n\tBETTER LUCK NEXT TIME.\n\n\tTHE WORD IS : "<<strupr(word)<<endl; } cout<<"\n\tWould you like to play again? [Y or N] : "; cin>>ch1; cin.get(); }while (ch1=='y' || ch1=='Y'); system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks


