fork download
  1. #include <stdio.h>
  2.  
  3. /* Prototype so main() can call it */
  4. int irishLicensePlateValidator(int yy, int halfYear, char county, int serial);
  5.  
  6. // **************************************************
  7. // Function: irishLicensePlateValidator
  8. //
  9. // Purpose:
  10. // Validates Irish license plate components for years 2013–2024
  11. // using a TWO-DIGIT year code.
  12. //
  13. // Rules:
  14. // 1) Year (yy): must be between 13 and 24.
  15. // 2) Half-year: must be 1 (Jan–Jun) or 2 (Jul–Dec).
  16. // 3) County: must be one of C, D, G, L, T, W (upper or lower case).
  17. // 4) Serial: integer from 1 to 999999 (1–6 digits).
  18. //
  19. // Returns:
  20. // 1 if all values are valid,
  21. // 0 otherwise.
  22. // **************************************************
  23. int irishLicensePlateValidator(int yy, int halfYear, char county, int serial)
  24. {
  25. /* Check two-digit year: must be 13..24 */
  26. if (yy < 13 || yy > 24) {
  27. return 0;
  28. }
  29.  
  30. /* Check half-year range */
  31. if (!(halfYear == 1 || halfYear == 2)) {
  32. return 0;
  33. }
  34.  
  35. /* Convert county to uppercase manually */
  36. if (county >= 'a' && county <= 'z') {
  37. county = (char)(county - ('a' - 'A'));
  38. }
  39.  
  40. /* Check allowed counties */
  41. if (!(county == 'C' || county == 'D' || county == 'G' ||
  42. county == 'L' || county == 'T' || county == 'W')) {
  43. return 0;
  44. }
  45.  
  46. /* Check serial number range */
  47. if (serial < 1 || serial > 999999) {
  48. return 0;
  49. }
  50.  
  51. /* Everything is valid */
  52. return 1;
  53. }
  54.  
  55. // **************************************************
  56. // Function: main
  57. //
  58. // Purpose:
  59. // Read plate components from the user and test the
  60. // irishLicensePlateValidator function.
  61. // **************************************************
  62. int main(void)
  63. {
  64. int yy; /* two-digit year: 13..24 */
  65. int halfYear; /* 1 or 2 */
  66. char county; /* C/D/G/L/T/W (upper or lower) */
  67. int serial; /* 1..999999 */
  68.  
  69. /* Read two-digit year */
  70. printf("Enter two-digit year (13..24): ");
  71. if (scanf("%d", &yy) != 1) {
  72. printf("INVALID (bad input)\n");
  73. return 1;
  74. }
  75.  
  76. /* Read half-year */
  77. printf("Enter half-year (1=Jan-Jun, 2=Jul-Dec): ");
  78. if (scanf("%d", &halfYear) != 1) {
  79. printf("INVALID (bad input)\n");
  80. return 1;
  81. }
  82.  
  83. /* Read county letter; skip leading whitespace */
  84. printf("Enter county (C/D/G/L/T/W): ");
  85. if (scanf(" %c", &county) != 1) {
  86. printf("INVALID (bad input)\n");
  87. return 1;
  88. }
  89.  
  90. /* Read serial number */
  91. printf("Enter serial (1..999999): ");
  92. if (scanf("%d", &serial) != 1) {
  93. printf("INVALID (bad input)\n");
  94. return 1;
  95. }
  96.  
  97. /* Validate and report */
  98. if (irishLicensePlateValidator(yy, halfYear, county, serial)) {
  99. printf("VALID\n");
  100. } else {
  101. printf("INVALID\n");
  102. }
  103.  
  104. return 0;
  105. }
Success #stdin #stdout 0s 5316KB
stdin
18
2
C
123456
stdout
Enter two-digit year (13..24): Enter half-year (1=Jan-Jun, 2=Jul-Dec): Enter county (C/D/G/L/T/W): Enter serial (1..999999): VALID