Input: A phrase that is stored as a string
Processing: transforming to lowercase in order to make comparison between each letter easier and know how many coincidences have been found. Storing number of coincidences of each letter in integer array vkr
attempting to print a letter from the string after the loops also prints smiley faces
code:
#include
#include // tolower
#include //transform
using namespace std;
int main()
{
string f;// phrase
int vkr[100];
//Initializing with zero
for (int n = 0; n < 100; n++)
{
vkr[n]=0;
}
// INPUT
cout << "Input a phrase " << endl;
getline(cin, f)
// getting l to use in for loop
int l = f.length();
// lowercase
transform(f.begin(), f.end(), f.begin(), ::tolower);
cout << f[0]; //prints letter
// PROCESSING
for (int n = 0; n < l; n++)
{
for (int j = 0; j < l; j++)
{
if (f[n] = f[j] && f[n] !=' ')
{
vkr[n]= vkr[n]+1;
vkr[j]= vkr[j]+1;
}
}
}
// OUTPUT
cout << f[0]; //prints smiley face
for (int n = 0; n < l; n++)
{
cout << f[n] << " = " << vkr[n] << " coincidences " << endl;
}
return 0;
}