# Thread: Simple problem for you guys - school proj

1. ## Simple problem for you guys - school proj

Hello, I am having trouble finishing this code, It converts whatever seven letters you type into the corresponding numbers on a phone. example A = "2" D = "3" G="4" ect. So It prompts a user for seven letter and it then outputs the phone number from those numbers. Everything works fine except I can't figure out how to put a dash after the third number. My output looks like this-- 5558888 I need it to output 555-8888. I also need it to print out a "#" if a lowercase letter is inputed. Thanks in advance for any help. Here is my code....
Code:
```#include <iostream>
#include <string>

using namespace std;

int main()
{
int dum = 0;

string input;
string bleh;
string str2 = "ABC", str3 = "DEF", str4 = "GHI",
str5 = "JKL";
string str6 = "MNO", str7 = "PQRS", str8 = "TUV",
str9 = "WXYZ";

cout << "Please enter a Seven letter word, all uppercase ";
getline(cin, input);

if (input.length() !=7)
{
cout << "The word you typed in is not seven characters in length";
return 1;
}

while (dum <= 6)
{
bleh = input.substr(dum,1);

if (str2.find(bleh) != string::npos)
{
cout << "2";

}
else if (str3.find(bleh) != string::npos)
{
cout << "3";

}

else if (str4.find(bleh) != string::npos)
{
cout << "4";
}
else if (str5.find(bleh) != string::npos)
{
cout << "5";
}
else if (str6.find(bleh) != string::npos)
{
cout << "6";
}
else if (str7.find(bleh) != string::npos)
{
cout << "7";
}
else if (str8.find(bleh) != string::npos)
{
cout << "8";
}
else if (str9.find(bleh) != string::npos)
{
cout << "9";
}

dum++;

}
return 0;
}```

2. u just need a cout after the third number like this:

cout <<"-";

that would go after the third and before the 4th

3. ## ?

I'm not following you, put it after the third number? I know that is what I want to do, however the third number changes every time so how do I tell it to put a dash in the 4th space?

4. After the if else statements that check what number to put, and before the dum++ add these lines:

Code:
```if(dum == 2){

cout << "-";

}```
So that will output a "-" when dum is equal to 2, which is the third number.

5. in your output of the third number u want it to be

cout<<"number here"<<"-";

even if your number chnages the "-" will always be there with it....that more clear?

6. Welcome to the world of parsing! ha. My personal favorite pastime...

Code:
```
char *ToTele(char input[]){
int i, j;
int length = strlen(input);
char temp[length+1];

for(i = 0, j = 0; i < length; i++, j++) {
if(i == 3) {
temp[j] = '-';
j++;
continue;
}
if(input[i] >= 'a' && input[i] <= 'z') {
temp[j] = '#';
}
else {
switch(input[i]) {
case 'A': case 'B': case 'C':
temp[j] = '1';
break;
//...continue like so...
default:
i++;
continue;
}
}
temp[j] = 0;

return strcpy(input, temp);
}
}```

7. ahhh thank you I only had one "=" in my dum == 2 line, thanks

8. Sebastiani, your code is not very portable.

Code:
```int length = strlen(input);
char temp[length+1];```
should be rewritten using new