Answer to Question #27959 in C++ for bashar
write a program that will input a sentence ending with a dot, then find the number of letters and the number of words in this sentence.
1
2013-04-08T11:18:47-0400
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
#include <memory.h>
#include <ctype.h>
using namespace std;
int main() {
char q;
char prev = ',';
int cnt_letters, cnt_words;
cnt_letters = cnt_words = 0;
for (;;) {
& scanf("%c", &q);
& if (q == '.') break;
& if (isalpha(q)) {
cnt_letters++;
if (!isalpha(prev))
cnt_words++;
& }
& prev = q;
}
printf("Number of letters: %d\n", cnt_letters);
printf("Number of words: %d\n", cnt_words);
return 0;
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
C++
Comments
Leave a comment