-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordCounter.cpp
More file actions
33 lines (27 loc) · 793 Bytes
/
WordCounter.cpp
File metadata and controls
33 lines (27 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
#include<string>
int main()
{
std::string String;
std::cout<<"Enter the string:"<<"\n";
std::getline(std::cin,String);
std::cout<<String<<"\n";
int i = 0;
int count = 0;
int dotCount = 0;
int smallLettersCount= 0;
while(++i<String.length()){
if(String[i]==' '){
count++;
}else if(String[i] == '.'){
dotCount++;
}else if(97<=int(String[i])<=122){
smallLettersCount++;
}
}
std::cout<<"Total number of words : "<<count+1<<"\n";
std::cout<<"Total number of characters(with full stop) : "<<String.length()-count<<"\n";
std::cout<<"Total number of characters(without full stop): "<<String.length()-count-dotCount<<"\n";
std::cout<<"Total Number of small letters: "<<smallLettersCount<<"\n";
return 0;
}