fork download
  1. #include <stdio.h>
  2.  
  3. //********************************************************
  4. // Function: irishLicensePlateValidator
  5. //
  6. // Purpose: Checks the validity of an Irish License Plate
  7. //
  8. // Parameters: year - 2 digit year license was issued
  9. // halfYear - half year period car was sold in
  10. // county - the irish county the car was
  11. // registered
  12. // snumber - 1-6 digit sequence number
  13. //
  14. // Returns: int
  15. //********************************************************
  16.  
  17. int irishLicensePlateValidator(int year, int halfYear, char county, int snumber)
  18. {
  19. char validCounties[] = {'c', 'C', 'd', 'D', 'g', 'G', 'l', 'L', 't', 'T', 'w', 'W'}; // array of valid county abbreviations
  20.  
  21. int i; // loop index
  22.  
  23. // varying conditions that test validity:
  24. // - if any of the conditions are met, the code stops and returns a 0 to indicate the plate is not valid
  25. // - if none of the conditions are meet, the code goes all the way through and returns a 1 to indicate the plate is valid
  26.  
  27. // check to see if the year is between 13 and 24
  28. if (year < 13 || year > 24)
  29. {
  30. return 0;
  31. }
  32.  
  33. // check to see if the half-year period is 1
  34. // if not, check to see if it is 2
  35. if (halfYear != 1)
  36. {
  37. if (halfYear != 2)
  38. {
  39. return 0;
  40. }
  41. }
  42.  
  43. // A loop to check the character vs the validCounties array
  44. // Alternatively, you could also do this with a series
  45. // of checks within a switch statement as well
  46. for (i = 0; i < 12; ++i)
  47. {
  48. if (validCounties[i] == county)
  49. {
  50. break;
  51. }
  52. }
  53.  
  54. // if all country codes were checked, and nothing matched
  55. // the country code would be 12 at this point, and would
  56. // indicate that the country code is invalid
  57. if (i == 12)
  58. {
  59. return 0;
  60. }
  61.  
  62. // since the maximum is 6 digits, the number cannot be higher than 999999
  63. // and can't be less than zero as well. 1 is the lowest number
  64. if (snumber <= 0 || snumber > 999999)
  65. {
  66. return 0;
  67. }
  68.  
  69. // if the compiler makes it all the way here, the plate must be valid and
  70. // therefore returns TRUE (which is a value of 1)
  71. return 1;
  72.  
  73. } //irishLicensePlateValidator
  74.  
  75.  
  76. int main(void) {
  77. // your code goes here
  78. return 0;
  79. }
  80.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty