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

Write a C++ program that inputs a single letter and prints out the corresponding

ID: 3620177 • Letter: W

Question

Write a C++ program that inputs a single letter and prints out the corresponding digit on the telephone.
The letters and digits on a telephone are grouped this way:
2 = ABC 4 = GHI 6 = MNO 8 = TUV
3 = DEF 5 = JKL 7 = PRS 9 = WXY
No digits correspond to either Q or Z. For these two letters, your program should print a message
indicating that they are not used on a telephone. If a letter in lower case or a non-alphabetic character is
entered, your program should indicate that there is no matching digit for such character.
The input of your program should be:
Please enter a single letter in upper case, and I will tell you what
the corresponding digit is on the telephone:
Examples of outputs are:
Supposing Z was entered: Sorry, but there is no digit on the telephone that corresponds to Z.
Supposing b was entered: Sorry, but b is an invalid input.
Supposing A was entered: The digit 2 corresponds to the letter A on the telephone.

Show that your program works by using at least 5 test cases, illustrating that all three cases listed above
are produced. You may only use the commands we have covered. That is, do not use looping for this
program.
Have your program send the output to both the screen and an output file. To have all the outputs appear
in the same output file, use the following to open the output file
outFile.open("hw2Output.txt", ios::app);
Note that you do not have to use the names outFile or hw2Output.txt .
Make sure that your name gets printed in the output file.




I ran this but still getting errors.....


#include<iostream>
#include<fstream>


using namespace std;

int main()
{
char c;
int n,x;
cout<<"Please enter a single letter in upper case, and I will tell you what the corresponding digit is on the telephone: ";
cin>>c;
n=c;
fstream myfile;
myfile.open("hw2Output.txt", ios::app);




if(n>=65&&n<=91){

if(n==81||n==90){
cout<<"Sorry, but "<<c<<" is an invalid input.";
myfile<<"Sorry, but "<<c<<" is an invalid input.";
}
else{
switch(c){
case 'A': case 'B': case 'C': cout<<" 2";x=2;break;
case 'D': case 'E': case 'F': cout<<" 3";x=3;break;
case 'G': case 'H': case 'I': cout<<" 4";x=4;break;
case 'J': case 'K': case 'L': cout<<" 5";x=5;break;
case 'M': case 'N': case 'O': cout<<" 6";x=6;break;
case 'P': case 'R': case 'S': cout<<" 7";x=7;break;
case 'T': case 'U': case 'V': cout<<" 8";x=8;break;
case 'W': case 'X': case 'Y': cout<<" 9";x=9;break;

}
myfile<<x;
}

}
else{
cout<<"Sorry, but there is no digit on the telephone that corresponds to "<<c<<".";
myfile<<"Sorry, but there is no digit on the telephone that corresponds to "<<c<<".";
}
myfile.close();
return 0;

}

Explanation / Answer

When declaring a char, be sure to put ' ' around the string. such as 'c'

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