Trouble with assignment. Please advise!

This is the question:
To make phone numbers easier to remember, some companies use letters to show their phone numbers. For example, using letters, the telephone number 438 5626 can be shown as GET LOAN. In some cases, to make numbers more meaningful, companies may use more than seven letters. For example, 225 5466 can be displayed as CALL HOME, which uses eight letters.
Write a C++ program that reads a list of telephone numbers expressed in capital letters from a text file and converts the telephone numbers in capital letters, to the corresponding telephone numbers in digits. Each converted phone number should be displayed on the console in both formats, alphabetic and digital. At the same time, the program creates another file in which the telephone numbers appear in digital format, one number per line. Allow the user to specify the name of the input file, as well as the name of the output file.
Apply the following convention: If a number consists of more than seven letters, only the first seven letters are processed. A space is displayed between the third and fourth digits. Letters A, B and C corresponds to digit 2; letters D, E and F to digit 3; letters G, H and I to digit 4; letters J, K and L to digit 5; letters M, N and O to digit 6; letters P, Q R and S to digit 7; letters T, U and V to digit 8; and letters W, X, Y and Z to digit 9. If any other character is encountered, a * is displayed.
The input file contains the following data, with one number per line:
CALL HOME
GET LOAN
Hi THERE
BYE FOR NOW
HELP ME PASS
For example, once the first number in the input file has been processed, the console window should display the following:
CALL HOME 225 5466.
The output file should now also contain the number:
225 5466



(code)

#include <iostream>
#include <fstream>

using namespace std;

int main()
{

ifstream myFile1("NumbersAndLetters.txt");

char sentence1;
string sentence, word1, word2, word3;
int num, i;

while(getline (myFile1, sentence, '\n' ))
{
cout<< sentence;

}

sentence = sentence1;

switch(sentence1)
{
case 'A':
case 'a':
case 'B':
case 'b':
case 'C':
case 'c':
cout<<"2";
cin >>sentence1;
break;
case 'D':
case 'd':
case 'E':
case 'e':
case 'F':
case 'f':
cout<<"3";
cin>>sentence1;
break;
case 'G':
case 'g':
case 'H':
case 'h':
case 'I':
case 'i':
cout<<"4";
cin>>sentence1;
break;
case 'J':
case 'j':
case 'K':
case 'k':
case 'L':
case 'l':
cout <<"5";
cin>>sentence1;
break;
case 'M':
case 'm':
case 'N':
case 'n':
case 'O':
case 'o':
cout <<"6";
cin >> sentence1;
break;
case 'P':
case 'p':
case 'Q':
case 'q':
case 'R':
case 'r':
case 'S':
case 's':
cout <<"7";
cin >> sentence1;
break;
case 'T':
case 't':
case 'U':
case 'u':
case 'V':
case 'v':
cout <<"8";
cin >> sentence1;
break;
case 'W':
case 'w':
case 'X':
case 'x':
case 'Y':
case 'y':
case 'Z':
case 'z':
cout <<"9";
cin >> sentence1;
break;

}
return 0;
}
(/code)
while(getline (myFile1, sentence, '\n' ))
I honestly have no idea what this is going to do with a single char.

sentence = sentence1;
why? pointless copy?

cin >> sentence1; why is this happening, why is it not reading from the file here?

it looks like you have a solid idea (the switch) but don't see how to process the file.
I suggest you use getline() on a string, then process the string in a loop, for each string in the file...
roughly

string s;
while(file has lines read a line into s)
for (s.length())
{
switch s[index]… etc
}



> while(getline (myFile1, sentence, '\n' ))
> I honestly have no idea what this is going to do with a single char.
`sentence' is a std::string
`sentence1' is a char

> sentence = sentence1;
> why? pointless copy?
`sentence1' is unitinialised
I guess was trying to invoke undefined behaviour


@OP: write pseudocode first
Topic archived. No new replies allowed.