Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Any direction or suggestions would be greatly appreciatedI have a class assigmen

ID: 3530116 • Letter: A

Question

Any direction or suggestions would be greatly appreciatedI have a class assigment C++ program, that prompts you to type in a phone number and it will return the all the letterss equences associated with the phone keypad. For example if I type in 800-555-5555 it will return: T00 JJJ JJJJ U00 KKK KKKK V00L LLL LLLL The code is written to be identical for both digits but what i actually get as an output if i type in 23 for example is : AC BC CC It will not go to DEF the same goes with any other number it just repeats the letter for the last digit. I started with two numbers and figured to work up to more numbers, I've googled for ideas but cant figure out why the code is not working with the second digit, this is the code so far : #include #include using namespace std; int main() { char choice, first, second; int dig1, dig2, numPoss1, numPoss2, number; cout << " Convert from number to word or word to number? (n/w): "; cin >> choice; if(choice == 'n') { cout << " Enter a two-digit number: "; cin >> number; dig1 = number/10; dig2 = number - 10*dig1; cout << " You entered " << dig1 << dig2 << endl; if(dig1 == 1) numPoss1 = 1; else if(dig1 == 7 || dig1 == 9) numPoss1 = 4; else numPoss1 = 3; //cout << "numPoss1 = " << numPoss1 << endl; if(dig2 == 0 || dig2 == 1 ) numPoss2 = 1; else if(dig2 == 7 || dig2 == 9) numPoss2 = 4; else numPoss2 = 3; //cout << "numPoss2 = " << numPoss2 << endl; for(int i = 0; i < numPoss1; ++i) { if(dig1 == 1) first = '1'; else if(dig1 < 7) first = (char)((dig1-2)*3 + 65 + i) cout << first << endl; else if(dig1 == 7) first = (char)(80+i); else if(dig1 == 8) first = (char)(84+i); else if(dig1 == 9) first = (char)(87+i); //cout << "first = " << dig1 << " and char " << first << endl; for(int j = 0; j < numPoss2; ++j) { if(dig2 == 0) second = '0'; else if(dig2 == 1) second = '1'; else if(dig2 < 7) second = (char)((dig1-2)*3 + 65 + j); else if(dig2 == 7) second = (char)(80+j); else if(dig2 == 8) second = (char)(84+j); else if(dig2 == 9) second = (char)(87+j); cout << "second = " << dig2 << " and char " << second << endl; } cout << first << second << endl; } } else if(choice == 'w') {//write code for choice == w } return 0; }

Explanation / Answer

I think i have helped. see this.

In the second for loop you have written

first = (char)((dig1-2)*3 + 65 + i) , same thing as in first for loop


i have changed this to

first = (char)((dig2-2)*3 + 65 + i)


now its printing def also.

Please rate 5 if it helps you.

----------------------------------------------


#include<iostream.h>
#include<stdlib.h>
using namespace std;
int main()
{
char choice, first, second;
int dig1, dig2, numPoss1, numPoss2, number;
cout << " Convert from number to word or word to number? (n/w): ";
cin >> choice;
choice='n';
if(choice == 'n')
{
cout << " Enter a two-digit number: ";
cin >> number;

dig1 = number/10;
dig2 = number;
cout << " You entered " << dig1 << dig2 << endl;
if(dig1 == 1) numPoss1 = 1;
else if(dig1 == 7 || dig1 == 9)
numPoss1 = 4;
else numPoss1 = 3;
//cout << "numPoss1 = " << numPoss1 << endl;
if(dig2 == 0 || dig2 == 1 )
numPoss2 = 1;
else if(dig2 == 7 || dig2 == 9)
numPoss2 = 4;
else numPoss2 = 3;
//cout << "numPoss2 = " << numPoss2 << endl;
for(int i = 0; i < numPoss1; ++i)
{
if(dig1 == 1)
first = '1';
else if(dig1 < 7)
first = (char)((dig1-2)*3 + 65 + i) ;
//cout << first << endl;
else if(dig1 == 7)
first = (char)(80+i);
else if(dig1 == 8)
first = (char)(84+i);
else if(dig1 == 9)
first = (char)(87+i);
//cout << "first = " << dig1 << " and char " << first << endl;
for(int j = 0; j < numPoss2; ++j)
{
if(dig2 == 0)
second = '0';
else if(dig2 == 1)
second = '1';
else if(dig2 < 7)
second = (char)((dig2-2)*3 + 65 + j);
else if(dig2 == 7)
second = (char)(80+j);
else if(dig2 == 8)
second = (char)(84+j);
else if(dig2 == 9)
second = (char)(87+j);
cout << "second = " << dig2 << " and char " << second << endl;
}
cout << first << second << endl;
}
}
else if(choice == 'w')
{
//write code for choice == w
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote