I have tried to structure my program but im stuck at this point. I have a file that contains phone phrases on each line (1-900-WINNING) is one of the phrases, if i get more digits than a phone number requires i must ignore the remainder. This data is coming from a file. Im just not understanding it, maybe i shouldn't read my data in as a string? . I am suppose to use a switch statement in my solution. I was thinking about doing a myFile.get(x) but i just dont understand how to put that into a string. Sometimes i understand it by seeing it done. please help.
the output should look like this
1-800-Free-Willy -> 1-800-373-3945
heres my program so far
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
ifstream inFile;
string phrase;
char x;
inFile.open("abc.txt");
inFile >> phrase;
while(inFile)
{
inFile.get(x);
cout << setw(17) << phrase << "-> ";
cout << endl;
if (( x >= 'A' && x <= 'Z') || ( x >= 'a' && x <= 'z') || ( x >= 0 && x <= 9 ))
{
switch (x)
{
case 'A':
case 'a':
case 'B':
case 'b':
case 'C':
case 'c':
case '2':
cout << "2";
break;
case 'D':
case 'd':
case 'E':
case 'e':
case 'F':
case 'f':
case '3':
cout << "3";
break;
case 'G':
case 'g':
case 'H':
case 'h':
case 'I':
case 'i':
case '4':
cout << "4";
break;
case 'J':
case 'j':
case 'K':
case 'k':
case 'L':
case 'l':
case '5':
cout << "5";
break;
case 'M':
case 'm':
case 'N':
case 'n':
case 'O':
case 'o':
case '6':
cout << "6";
break;
case 'P':
case 'p':
case 'Q':
case 'q':
case 'R':
case 'r':
case 'S':
case 's':
case '7':
cout << "7";
break;
case 'T':
case 't':
case 'U':
case 'u':
case 'V':
case 'v':
case '8':
cout << "8";
break;
case 'W':
case 'w':
case 'X':
case 'x':
case 'Y':
case 'y':
case 'Z':
case 'z':
case '9':
cout << "9";
break;
}
}
}
system("pause");
return 0;
}