fork download
  1. #include <stdio.h>
  2.  
  3. int irishLicensePlateValidator(int year, int halfYear, char county, int snumber);
  4.  
  5. int main(void) {
  6. printf("%i", irishLicensePlateValidator (19, 1, 'c', 124596));
  7.  
  8. return 0;
  9. }
  10.  
  11. int irishLicensePlateValidator(int year, int halfYear, char county, int snumber)
  12. {
  13. char validcounties[] = {'c', 'C', 'd', 'D', 'g', 'G', 'l', 'L', 't', 'T', 'w', 'W'}; // array of valid county abbreviations
  14.  
  15. int i; // loop index
  16.  
  17. // varying conditions that test validity
  18. // if any of the conditions are met, the code stops and returns a 0 to indicate the plate is not valid
  19. // if none of the conditions is meet, the code goes all the way through and returns a 1 to indicate the plate is valid
  20.  
  21. // checks to see if the year is between 13 and 24
  22. if (year < 13)
  23. {
  24. return 0;
  25. }
  26. if (year > 24)
  27. {
  28. return 0;
  29. }
  30. // checks to see if the halfyear period is 1.
  31. // if not, checks to see if it is 2
  32. if (halfYear != 1)
  33. {
  34. if (halfYear != 2)
  35. {
  36. return 0;
  37. }
  38. }
  39. // loop to check the char vs the validcounties array
  40. for (i = 0; i < 12;)
  41. {
  42. if (validcounties[i] == county)
  43. {
  44. i = 12;
  45. }
  46. if (validcounties[i] != county)
  47. {
  48. i++;
  49. }
  50. if (i == 12)
  51. {
  52. return 0;
  53. }
  54. }
  55. // since the maximum is 6 digits, the number cannot be higher than 999999
  56. // since there are no leading zeroes the smallest number can only be 100000
  57. if (snumber > 999999)
  58. {
  59. return 0;
  60. }
  61. if (snumber < 100000)
  62. {
  63. return 0;
  64. }
  65.  
  66. return 1;
  67.  
  68. } //irishLicensePlateValidator
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
1