Hello. I need some help with my program wich shoulc calculate letters in a sentence and then print out the longest, shortest, how many words, and what's the avrage value.
Thanks for some help. :)
#include <iostream>
#include <string>
using namespace std;
int main()
{
int word;
int n;
string sentence;
string min;
string max;
word=0;
n=0;
while( cin >> sentence)
{
word++;
n += sentence.size();
if(sentence.size() >= max.size())
{
max = sentence;
}
else if (sentence.size() < min.size())
{
min = sentence;
}
}
if (word == 0)
{
cout << "You need to write someting" << endl;
}
else
{
cout << "The text got " << word << " words." <<
"The shortest word was \"" << min << "\" = " << min.size() <<
"The longest word was \"" << max << "\" = " << max.size() <<
"The average value is " << n / word << endl;
}
return 0;
}