ok hello again
I got my program done just having trouble with something. I need to find all instances of a letter in a string, ex: Alpha: has two 'a'. My program only reads the first 'a'. This is what my prog looks like.
what u guys think.. man this gets me anoyed lolCode:#include<iostream> //Includes the I/O library using namespace std; char loopcount; int tries; //All the different type of global variables used string word; char letter; string plar; int i; char n; int main() { cout<< "Please enter you name: "; // Enters the plaers name cin>>plar; cout << "Please enter a word: "; // Enters a word cin>> word; //Displays alot of end lines to hide the word that is to be guessed cout<< endl<<endl<<endl<<endl<<endl<<endl; cout<< endl<<endl<<endl<<endl<<endl<<endl; cout<< endl<<endl<<endl<<endl<<endl<<endl; cout<< endl<<endl<<endl<<endl<<endl<<endl; cout<< endl<<endl<<endl<<endl<<endl<<endl; cout<< endl<<endl<<endl<<endl<<endl<<endl; cout<< endl<<endl<<endl<<endl<<endl<<endl; cout<< endl<<endl<<endl<<endl<<endl<<endl; cout << "Please enter the amount of tries: "; //Enters the amount of tries cin>> tries; string guess(word.size(), '*'); // use the word and converts to '*' cout << guess <<endl; for (i = tries; i>=0; i--) // Used a forloop to decrement the tries { cout<<"Please enter a letter to be guessed: "; cin>> letter; int pos = word.find(letter); // Find if the letter is in the word and // displays it guess[pos] = letter; if (pos != string::npos) { cout<<"Correct. You now have: "<<i<< " left"<<endl; cout <<guess<<endl; } else cout<<"Wrong! You now have: "<<i<< " left"<<endl; if (tries == 0) { cout<<"Sorry you guessed wrong, the word was: "<<word<<endl; return 1; } } //If word was guessed correctly then a happy face will be displayed if (guess == word) { cout<<"Great Job! "<<plar<< " YOU WIN!"<<endl; return 1; } } cout <<plar<< " YOU LOSE! :( The word was: "<< word<<endl; return 0; } }
thanks again



LinkBack URL
About LinkBacks


