I have homework that I flew over until I got to this last step, and now I'm at a standstill, I would really appreciate help.
The premise of the project is to create a file of possible words with a phone number. The user must enter a number with the format '### - ####'. The code then extracts the hyphen and sends the phone number to the wordGenerator method. I know that everything works up to this point. When the time comes for release, the different possibilities of words are where I have a problem. This is what my method looks like:
Unfortunately, they gave me a code skeleton and was told to fill in the blanks to complete the task. Wherever comments are blocked (/ * * /), I have to fill in the code.
I'm not sure what I need to do to get the correct format for possible words. I tried to find google, but all the results that I found use a much simpler (in my opinion) switch statement to achieve this, and I'm limited to the pattern: (
All help is welcome, even a push in the right direction.
Edit: I just thought about something else. I feel that if someone can even help me figure out how to iterate through the characters of phoneLetters [] individually rather than a block, this will be a significant step forward. Example: when reading the phone number in number “2” instead of printing “ABC”, type “A” for all possible combinations, then go to “B”.
Edit: Here is my main ():
int main() { int phoneNumber[ 7 ] = { 0 }; // holds phone number // prompt user to enter phone number cout << "Enter a phone number (digits 2 through 9) " << "in the form: xxx-xxxx\n"; // loop 8 times: 7 digits plus hyphen; // hyphen is not placed in phoneNumber for ( int u = 0, v = 0; u < 8; u++ ) { int i = cin.get(); // test if i is between 0 and 9 if ( i >= '0' && i <= '9' ) phoneNumber[ v++ ] = i - '0'; } // end for wordGenerator( phoneNumber ); // form words from phone number return 0; } // end main
source share