Advertisement
BlackWolfy

Count the number of times a symbol appears in a text

Feb 6th, 2023
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main()
  5. {
  6.     string text;
  7.     char symbol;
  8.     int counter = 0;
  9.     cout << "Enter text: "<<endl;
  10.     getline(cin, text);
  11.     cout << "The number of times a symbol has appeared will be counted. Enter the symbol you want to check: "<<endl;
  12.     cin >> symbol;
  13.     for (int i = 0; i < text.length(); i++) {
  14.         if (text[i] == symbol) {
  15.             counter++;
  16.         }
  17.     }
  18.     cout << "The symbol has appeared "<<counter<<" times!";
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement