I need to write program that inputs a scrambled word and compares it against a pre-determined list of words. I am first checking for length, then if a match is found, sending them to a function to compare the letters. I can't seem to get the loops right. Here is what I have so far:
I would love any suggestions on how to make this work!Code:Code: #include <cstring> #include <cstdlib> #include <iomanip> #include <fstream> #include <iostream> #include <string> using namespace std; bool check(string, string); int main() { string scrambled; string PossibleWord [13]={"will", "check", "it", "against", "list", "and", "return", "hello", "True", "or", "False", "Swap"}; cout << "Please enter scrambled word: "; cin >> scrambled; for (int i=0; i<13; i++) { if (scrambled.size()==PossibleWord[i].size()) { if (check(PossibleWord[i], scrambled)) { cout<< "the word is " << PossibleWord[i]<<endl; break; } } else cout<< "the word is not found"<<endl; } system ("pause"); } bool check(string p, string s) { bool match; int count=0; int psize= p.size(), ssize= s.size(); for (int i=0; i< psize; i++) { for (int d=0; d< ssize; d++) { if (p[i]==s[d]) { cout << "Match with possible's "<< p[i] << " and scrambled's " << s[d]<< endl; count++; } } } cout << "Count is "<< count <<endl; if (count==psize) { match=true; return match; } else match=false; return match; }




Reply With Quote