63 808
Assignments Done
99,5%
Successfully Done
In August 2018

Answer to Question #27959 in C++ for bashar

Question #27959
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.
Expert's answer
#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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions