thanks cyberfish. With the array I was able to count how many of each letter there is. Now how can I limit the output to only output the ones that have a value greater than 1? If the letter is not in the text, I would like to not print it out. How would I do that also with the characters? including the difference when they are CAPS or lower case?
here is my new code after i added the arrray
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string word;
int letter[126]={0};
int count=0, a;
char ch[126];
ifstream fin;
fin.open("input.txt");
if (fin.fail())
{
cout<<"Couldn't read file. \n";
cin.get();
return 0;
}
while(!fin.eof())
{
fin>>word;
cout<<word<<" ";
++count;
a=word.length();
for(int i=0; i<a;++i)
{
ch[i]=word[i];
++letter[ch[i]];
}
}
cout<<"\nThere are: "<<count<<" words";
for(int i=0; i<126;++i)
{
cout<<" "<<letter[i]<<endl;
}
fin.close();
cout<<"\nPress enter to exit";
cin.get();
return 0;
}