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....
[edit]Code tags added by Hammer. Please use them in future.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; }



LinkBack URL
About LinkBacks


