determining whether a user input is a valid hexadecimal 1-9 a-f

ساخت وبلاگ

Vote count: 0

I have been asked to write a simple program that asks the user to type in a series of digits, one at a time, that will be checked by the program to ensure they are valid digits for a hexadecimal number. The program should repeatedly ask the user for a digit and, after each digit is entered, check that it is valid. If the digit is invalid the program will terminate with an error saying "That digit is invalid." otherwise, it will continue receiving digits from the user. When the user finishes entering their digits, they should simply press enter without typing anything. At this point, assuming all of the digits are valid, the program should output the entire string with a message informing the user it is a valid string. Below are some sample user interactions with the program. First, an example with invalid input:

Digit: a Digit: 4 Digit: 0 Digit: b Digit: k k is not a valid hexadecimal digit. ​

An example with valid input:

Digit: 1 Digit: 7 Digit: 2 Digit: b Digit: 9 Digit: 172b9 is a valid hexadecimal string. ​

And another more complex example of valid input:

Digit: 0 Digit: A Digit: f Digit: 2 Digit: 6 Digit: 5 Digit: 0Af265 is a valid hexadecimal string. ​

Note that if the user enters nothing, the program should output a message indicating that "The input was blank.":

Digit: The input was blank

asked 1 min ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 443 تاريخ : پنجشنبه 26 اسفند 1395 ساعت: 7:06