Question: Write a routine/function that takes as input a character c supposed to be an hexadecimal digit and returns an integer representing the value of the

 Write a routine/function that takes as input a character c supposed

Write a routine/function that takes as input a character c supposed to be an hexadecimal digit and returns an integer representing the value of the digit c. If c is not a hexadecimal digit, your function must return -1. Use this function to implement a program that prompts the user to enter a character c that represents an hexadecimal digit (Recall that c can be '0', I. .2. 8. '9'AB', C. D', , or F'). To simplify, we will use only uppercase letters for hexadecimal digits larger than 9. Your program must use the character type for the input. If the user enters a character 'x' that is NOT an hexadecimal digit, you must print out the error message: "The character x is invalid: x is not an hexadecimal digit". If the character c is an hexadecimal digit, your main program must return an integer representing the value of the digit and print out that value in decimal. Example l: If the user enters the character 4', your program must print out the value 4. Example 2: If the user enters the character B', your program must print out the value Example 3: If the user enters the character 'E, your program must print out the value 14. Example 4: If the user enters the character 't,your program must print out the error message: The character t is invalid: t is not a hexadecimal digit

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!