for (int i = 0; i < __________; _______)
{
getline(cin, words[ ____ ] );
[add a period to the end of the word]
}
int total = ____;
for (int n = 0; n < __________; _______)
{
int count = ____;
while ( _________[ ][ ] != '.')
{
count++;
}
cout << ________[ ] << " has " << ________ << "letters\n";
total = total + _____________;
}
cout << "Total number of letters is " << _________ << endl;
1
Expert's answer
2014-09-29T14:25:35-0400
#include <iostream> #include <string> using namespace std; int main() { int numStrings; cout << "Please enter ..."; cin >> numStrings; fflush(stdin); string* words = new string[numStrings];
for (int i = 0; i < numStrings; ++i) { getline(cin, words[i]); fflush(stdin); //[add a period to the end of the word] } int total = 0; for (int n = 0; n < numStrings; ++n) { int count = 0; while ( words[n][count] != '.') { count++; } cout << words[n] << " has " << count << " letters\n"; total = total + count; } cout << "Total number of letters is " << total << endl; delete[] words; return 0; }
Comments
Leave a comment