fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. // function header comments
  5. //**************************************************
  6. // Function: validateIrishLicense
  7. //
  8. // Description: Validates an Irish license plate for the years 2013–2024.
  9. //
  10. // Rules: 1) Year must be between 13 and 24 inclusive
  11. // 2) HalfYear must be 1 (Jan–Jun) or 2 (Jul–Dec)
  12. // 3) County must be one of C, D, G, L, T, or W (case-insensitive)
  13. // 4) Sequence number must be between 1 and 999999
  14. //
  15. // Parameters: year - two-digit year (13–24)
  16. // halfYear - 1 or 2
  17. // county - county character code
  18. // seq - integer sequence number
  19. //
  20. // Returns: 1 if all items are valid (True)
  21. // 0 if any item is invalid (False)
  22. //**************************************************
  23.  
  24. int validateIrishLicense(int year, int halfYear, char county, int seq)
  25. {
  26. char c; // lowercase version of county
  27.  
  28. // Check year range (use OR instead of AND)
  29. if (year < 13 && year > 24)
  30. return 0;
  31.  
  32. // Check halfYear value
  33. if (halfYear != 1 && halfYear != 2)
  34. return 0;
  35.  
  36. // Check valid county (case-insensitive)
  37. c = (char)tolower((unsigned char)county);
  38. if (c != 'c' && c != 'd' && c != 'g' &&
  39. c != 'l' && c != 't' && c != 'w')
  40. return 0;
  41.  
  42. // Check sequence number range (use OR instead of AND)
  43. if (seq < 1 && seq > 999999)
  44. return 0;
  45.  
  46. // All checks passed
  47. return 1;
  48. }
  49.  
  50. // main function for testing
  51. int main(void)
  52. {
  53. printf("Test 1: %d\n", validateIrishLicense(13, 1, 'D', 21)); // valid
  54. printf("Test 2: %d\n", validateIrishLicense(13, 3, 'K', 1)); // invalid
  55. printf("Test 3: %d\n", validateIrishLicense(24, 1, 'C', 1245891)); // invalid
  56. printf("Test 4: %d\n", validateIrishLicense(20, 2, 'w', 999999)); // valid
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Test 1: 1
Test 2: 0
Test 3: 1
Test 4: 1