#include <iostream> #include <string> #include <cctype> using namespace std; //T
ID: 3619157 • Letter: #
Question
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
//These functions explained below
void spaces();
void introduction();
int main()
{
string sentence;
char response;
int words = 0;
do
{
getline(cin, sentence);
for(inti = 0; i < sentence.length(); i++)
{
if(isspace(sentence[i]) ||(sentence[i] == ',') ||(sentence[i] == '.'))
{
words++;
while(isspace(sentence[i]) ||(sentence[i] == ',') ||(sentence[i] == '.'))
{
i++;
}
}
}
cout << words << endl;
//Asks the user he would like to go again anything other than (Y ory) the program ends
cout << "Would you like to go again (Yor y): ";
cin >> response;
cout << endl;
cin.ignore();
}while(response == 'Y' || response== 'y');
return 0;
}
Explanation / Answer
please rate - thanks I changed the loop to while, at some points you were incrementing itwice, skipping some letters, that's why you had a problem #include #include #include using namespace std; // These functions explained below void spaces(); void introduction(); int main() { string sentence; char response; int words = 0; int letters[26]={0}; int i; do { getline(cin, sentence); i=0; while(i 96) letters[sentence[i]-97]++; else letters[sentence[i]-65]++; i++; } } coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.