I have tired many thing, but the alphabet that it shows it sometimes wrong. But I am pretty sure the count is good, as in what is the most frequent one.
void ques1(){
vector<string> word;
string w;
int count = 1;
vector<string> word2;
cout << "Please enter some words: ";
while (cin >> w){
word.push_back(w);
}//while
int x = 0;
sort(word.begin(),word.end());
word2.push_back(word[0]);
for(int i = 1;i < word.size();i++){
if(word[i] == word[i-1]){
count++;
if(i == 1){
x = count;
}
}
else if(count > x){
word2.clear();
word2.push_back(word[i]);
x = count;
count = 1;
}
else if(count == x){
word2.push_back(word[i]);
count = 1;
}
else {
count = 1;
}
if(i == word.size() - 1){
if(count > x){
word2.clear();
word2.push_back(word[i]);
x = count;
count = 1;
}
else if(count == x){
word2.push_back(word[i]);
count = 1;
}
}//if
}//for
cout << endl << "The most frequently occuring words are: " << endl << endl;
for(int i = 0; i < word2.size();i++){
cout << x << " " << word2[i] << endl;
}//for
}//ques1

New Topic/Question
Reply



MultiQuote










|