The following assignment is presented:
Given a string of characters. Calculate how many times “ABBA” is used in it.
My code:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string aBBa = "Abbakiy Abbakum Abbak'evich";
int i = 0, j = 0;
cout << "Expression: " << aBBa << endl;
do {
if (aBBa[i] == 'а')
j++;
i++;
} while (aBBa[i] != '\0');
cout << "Quantity letters a: " << j << endl;
i = 0;
system("pause");
return 0;
}
I was only able to understand how to find the number of letters in the text, if I try to find it half-word in the same way (namely, in the fragment below I will write instead of a - abba),
if (aBBa[i] == 'а')
j++;
then the program will refuse to calculate anything (the value will be zero).