Here's how to convert a license plate into a car rental code:
- Ask the user for a license plate. A license plate consists of digits and capital letters of the alphabet only, like
607CPR21
, 123ABC4567
, 1F24
, or 98ZWXTY2
.
- Add up the ASCII values of the letters and the integer values of the digits, e.g.
6 + 0 + 7 + 67 + 80 + 82 + 2 + 1 = 245
for our first example above.
- Take this sum and map it onto a numeric representation of one of the 26 letters of the alphabet (where A’s numeric representation is 0, B’s numeric representation is 1, etc.). For example, 245 should map to an 11.
- Use this number (say 11) to determine the 11th letter in the alphabet after the letter A: the 11th letter after A is L.
- Combine the letter and the sum to make the car ID. So far, it's:
L245
.
- Extract the substring of letters out of the original license plate – in this case
CPR
. Convert the letters to lowercase and place the letters at the end of the car id to get – and print – the final answer: L245cpr