fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // **************************************************
  5. // Function: irishLicensePlateValidator
  6. //
  7. // Description: Validates an Irish License Plate
  8. // for the years between 2013 and 2024
  9. //
  10. // Parameters: year - two digit year (13 - 24)
  11. // halfYear - when car sold (1st half / 2nd half of year)
  12. // county - must be from C/c, D/d, G/g, L/l, T/t, or W/w
  13. // SSSSSS - a 1 to 6 digit sequence number
  14. //
  15. // Returns: 1 or 0 for true or false (whether it is valid)
  16. //
  17. // ***************************************************
  18. int irishLicensePlateValidator(int year, int halfYear, char county, int SSSSSS)
  19. {
  20.  
  21. // you can get most all values you need from the parameter values passed in
  22.  
  23. int valid = 1; // 0 or 1 variable returned at the end
  24. // add some conditional statement logic to check each parameter (switches, if/else, ...)
  25.  
  26. // checks whether year is outside the range of 2013-2024
  27. if((year < 13) || (year > 24))
  28. {
  29. valid = 0;
  30. }
  31.  
  32. // checks whether halfYear is incorrect (must be 1 or 2)
  33. if((halfYear != 1) && (halfYear != 2))
  34. {
  35. valid = 0;
  36. }
  37.  
  38. // checks if the county is valid
  39. switch(county)
  40. {
  41. case 'c': // Cork
  42. break;
  43. case 'C':
  44. break;
  45. case 'd': // Dublin
  46. break;
  47. case 'D':
  48. break;
  49. case 'g': // Galway
  50. break;
  51. case 'G':
  52. break;
  53. case 'l': // Limerick
  54. break;
  55. case 'L':
  56. break;
  57. case 't': // Tiperary
  58. break;
  59. case 'T':
  60. break;
  61. case 'w': // Waterford
  62. break;
  63. case 'W':
  64. break;
  65. default: // if it is none of the cases, invalid
  66. valid = 0;
  67. }
  68.  
  69. // checks if the sequence number is between 1 to 6 digits
  70. if ((SSSSSS < 1) || (SSSSSS > 999999))
  71. {
  72. valid = 0;
  73. }
  74.  
  75. return(valid);
  76. }
  77.  
  78. printf("Supposed to be true: %d", irishLicensePlateValidator(13, 1, 'D', 21));
  79. printf("\nSupposed to be false: %d", irishLicensePlateValidator(12, 1, 'D', 21));
  80. printf("\nSupposed to be false: %d", irishLicensePlateValidator(13, 3, 'D', 21));
  81. printf("\nSupposed to be false: %d", irishLicensePlateValidator(13, 1, 'K', 21));
  82. printf("\nSupposed to be false: %d", irishLicensePlateValidator(13, 1, 'D', 1245891));
  83.  
  84. return 0;
  85. }
  86.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Supposed to be true: 1
Supposed to be false: 0
Supposed to be false: 0
Supposed to be false: 0
Supposed to be false: 0