fueanta

Letter Count on a paragraph

Sep 6th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. // Cpp program to count the letters on a paragraph and describe it precisely.
  2. // created on July, 2016
  3. // Author: fueanta
  4.  
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. int main(){
  9.     int small[26]={0},capital[26]={0};
  10.     cout << "Give your sentence please: ";
  11.     string sent;
  12.     getline(cin,sent); //passing &sent[0]
  13.     for (int i=0;sent[i]!='\0';i++){
  14.         if (sent[i]>='A' && sent[i]<='Z'){
  15.             capital[int(sent[i])-65]++;
  16.         }
  17.         else if (sent[i]>='a' && sent[i]<='z'){
  18.             small[int(sent[i])-97]++;
  19.         }
  20.     }
  21.     cout << "\n\nThe sentence has ";
  22.     for (int i=0;i<25;i++){
  23.         if (capital[i]>0){
  24.             cout << char(i+65) << " in " << capital[i] << " place(s), ";
  25.         }
  26.     }
  27.     for (int i=0;i<25;i++){
  28.         if (small[i]>0){
  29.             cout << char(i+97) << " in " << small[i] << " place(s), ";
  30.         }
  31.     }
  32.     cout << "\n\n";
  33.     return 0;
  34. }
Add Comment
Please, Sign In to add comment