-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path07_operators_precedence.cpp
More file actions
42 lines (36 loc) · 964 Bytes
/
07_operators_precedence.cpp
File metadata and controls
42 lines (36 loc) · 964 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
34
35
36
37
38
39
40
41
42
/*
Write a program to calculate digits, whitespaces,alphabets & other characters terminated by $.
*/
#include <iostream>
using namespace std;
int main(){
int digits=0;
int alphabets=0;
int spaces=0;
int other=0;
char ch;
cout<<"Enter you characters :";
ch = cin.get(); // Note: If you want to read spaces then use cin.get()
// cin>>ch;
while(ch!='$'){
if(ch>='0' and ch<='9'){
digits++;
}
else if((ch>='a' and ch<='z') or (ch>='A' and ch<='Z')){
alphabets++;
}
else if(ch==' ' or ch=='\n' or ch=='\t'){
spaces++;
}
else{
other++;
}
ch = cin.get(); // Note: If you want to read spaces then use cin.get()
// cin>>ch;
}
cout<<"Digits :"<<digits<<endl;
cout<<"Alphabets :"<<alphabets<<endl;
cout<<"Spaces :"<<spaces<<endl;
cout<<"Other :"<<other<<endl;
return 0;
}