I have done this code under here.
What is does is:
you write a sentence and it will count words, shortest word etc.
when i compile it goes fine, but when i run it it doesnt write aout any anserws.
help me!
Code:
#include <iostream>
using namespace std;
int main () {
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
int length, largest, smallest, average=0;
string word;
char firstchar, lastchar, space;
cout << "Enter your lines:" << endl;
while (cin >> word) {
counter1++;
length = word.length();
firstchar = word[0];
if (firstchar >= 'A' && firstchar <= 'Z')
counter2++;
if (counter1 == 1)
largest = smallest = length;
else if (length > largest)
{
largest = length;
}
else if (length < smallest)
{
smallest = length;
}
lastchar = word[word.length()-1];
if (lastchar == '!' || lastchar == '?' || lastchar == '.')
counter3++;
average += length;
}
cout << "There were " << counter1 << " words entered" << endl;
cout << "There were " << counter2 << " capital letters." << endl;
cout << "The longest string had " << largest << " letter(s)." << endl;
cout << "The shortest string had " << smallest << " letter(s)." << endl;
cout << "There were " << counter3 << " sentences entered." << endl;
cout << "The average word length is " << (average / counter1) << " characters." << endl;
return 0;
}