Print Friendly and PDF
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(int argc, const char * argv[])


{


char set2[] = {'a','b','c'};
char set3[] = {'d','e','f'};
char set4[] = {'g','h','i'};
char set5[] = {'j','k','l'};
char set6[] = {'m','n','o'};
char set7[] = {'p','q','r','s'};
char set8[] = {'t','u','v'};
char set9[] = {'w','x','y','z'};
char space[] = {" "};
char sentence[80];
cout << "Add Text" << endl;


cin.getline(sentence,80);

cout << sentence << endl;
int spaceCount = 0;
int numCount = 0;
for (int i = 0; i < strlen(sentence); i++) 

{
if (strpbrk(sentence, set2))
{
numCount++;
continue;
}
else if (strpbrk(sentence, set3))
{
numCount++;
continue;
}
else if (strpbrk(sentence, set4))
{
numCount++;
continue;
}
else if (strpbrk(sentence, set5))
{
numCount++;
break;
}
else if (strpbrk(sentence, set6))
{
numCount++;
break;
}
else if (strpbrk(sentence, set7))
{
numCount++;
break;
}
else if (strpbrk(sentence, set8))
{
numCount++;
break;
}
else if (strpbrk(sentence, set9)) {
numCount++;

break;
else if (strpbrk(sentence, space)) {
spaceCount++;
break;
}
}
cout << "The number of times we need to press keys to write your sentence is: " << numCount << endl;
return 0;
}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: