letter count

I write a program that count # of letters in a text file and now I need to tweak it a little bit using functions that:
1-take character as input parameter and returns its occurrence frequency in the input file
2-takes character as input parameter and returns its percentage of time it occurred in the input file.
3-display the character with the highest occurrence
4-display the character with the fewest occurrence
Okay. So what is your question?
add functions
Last edited on
Well you already have option 1 done right? You just have to ask for which character they want to know about.
Option 2 is just taking the character the user input's count and dividing it by letter_count and multiplied by 100 for percent.
Option 3 is traversing through your frecount and seeing which is the highest.
Option 4 is the same as option 3, except you are looking for the lowest.

Options 3&4:
1
2
3
4
5
6
for(int max=frecount[0], min=frecount[0], inti=1; i<27; i++)
{
    if(max<frecount[i]) max = frecount[i];
    if(min>frecount[i]) min = frecount[i];
}
//note: this does not check if two or more characters tie for min or max counts 
kevin,

can you explain to me what you mean by ask for which character they want to know about? I lost you here
I mean ask them....
1
2
cout <<"Hey user tell me what character you want to know about: ";
cin.get(ch);

http://cplusplus.com/doc/tutorial/basic_io/
my function definition here:
1
2
3
4
5
6
7
8
9
char getAlpha()
{
  char ch;
  cout<<"how many characters you want to know about? : ";
  cin.get(ch);
  while (!isalpha(ch) && ch!= '.')
    cin.get(ch);
  return ch;
} 


when I call getAlpha() on main, nothing is happening, why is that?
getAlpha() should return a single char that is part of the alphabet. You should call it from main like this:
ch = getAlpha();
Last edited on
when I call getAlpha it prompt the user to enter how many character. will that be integer numbers? im getting confused here
Your function returns type char. It will never return an int type variable. You shouldn't even ask the question how many, but rather which one is what you should be asking. Please, go and read the tutorial. Perhaps the parts about variable types, functions, and the general input and output I linked to earlier.

Edit: Oops. Forgot to give you the link
http://cplusplus.com/doc/tutorial/
I would start with everything under: Basics of C++
Last edited on
for(int max=frecount[0], min=frecount[0], inti=1; i<27; i++)
{
if(max<frecount[i]) max = frecount[i];
if(min>frecount[i]) min = frecount[i];
}


how can I make this to check if two or more characters tie for min or max counts?

so far it is just picking a high value
Topic archived. No new replies allowed.