this is a piece of code I've made that asks the user to input a string of lowercase letters only, if not they'd have to input it again. Then, it scans through the string and outputs the amount of letters used in the string and the amount not used. It works perfectly and exactly the way I wanted it to...except when the string has a space in it. So for example, if the string is "asd fg" the output will be "3 letters used, 23 not used" when we can clearly see it needs to be "5 letters used, 21 not used." How do I fix this?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string inp;
int l_inp, i, un, in, ln;
un=0;
ln=26;
char alpha;
bool flag;
flag=false;
do
{
cout<<"Please Enter String of Lowercase Letters: ";
cin>>inp;
i=0;
while (inp[i]>=97 && inp[i]<=122)
i++;
if (inp[i]=='\0')flag=true;
l_inp=0;
if (inp[l_inp]=='\0')flag=false;
}
while (flag==false);
for (alpha='a';alpha<='z';alpha++)
{
for (in=0;inp[in]!='\0';in++)
{
inp[in];
}
std::size_t found = inp.find(alpha);
if (found!=std::string::npos)
{
un++;
ln--;
}
}
cout<<" "<<un<<" letters are used in the string"<<endl;
cout<<" "<<ln<<" letters are not used in the string"<<endl;
return 0;
}