Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (anonymous):

please need help with c++.........Write a program that reads from the user a letter, and prints out the digit value corresponding to this letter based on the encoding on a mobile phone's keypad. For example, for a, b, or c, the program would print the digit 1. If the letter entered is not one of the letters of the alphabet, print a value of -1. Use a switch statement

OpenStudy (anonymous):

The more naive approach would be something of the like: if (input_from_user == 'a' || input_from_user == 'b' || if input_from_user == 'c') printf("1\n"); if (input_from_user == 'd' || .... ) printf("2\n"); Now you can do it with the switch statemente, just remember to break out of the case, and you can bundle multiple cases together, i.e.: case 'a' : case 'b' : case 'c' : printf("1\n"); break; //more code P.S.: Consider other input, and consider the input of upper case letters also. Hope this was helpful :-)

OpenStudy (anonymous):

thank you that was really helpful

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!