#include <stdio.h>
int irishLicensePlateValidator(int year, int halfYear, char County, int Sequence);
int main(void) {
int year = 12; // year validity
int halfYear = 1; // halfyear validity
char County = 'c'; // county validity
int Sequence = 132456; // sequence validity
int validity = irishLicensePlateValidator(year, halfYear, County, Sequence);
year = 8; // testing validity for year
validity = irishLicensePlateValidator(year, halfYear, County, Sequence);
year = 15; // placeholder true value
halfYear = 3; // testing validity for half year
validity = irishLicensePlateValidator(year, halfYear, County, Sequence);
year = 15; // valid year
halfYear = 2; // valid halfyear
County = 'f'; // invalid county
validity = irishLicensePlateValidator(year, halfYear, County, Sequence);
year = 15; // valid year
halfYear = 2; // valid halfyear
County = 'C'; // valid county
Sequence = 12367432; // test invalid sequence
validity = irishLicensePlateValidator(year, halfYear, County, Sequence);
return 0;
}
//***********************************************************
// Function irishLicensePlateValidator
//
// Description : Ensure license plate is valid
//
// Parameters : int year - Valid year is 2 digits
// int halfYear - 1 and 2 is valid
// char County - Checked the character in license plate for validity
// sequence - Ensures we are not over 7 digits in our plate
//
// Returns : 1 for valid, 0 for invalid on any parameters
//
//***************************************************************
int irishLicensePlateValidator(int year, int halfYear, char County, int Sequence)
{
int valid = 1; // initialize valid license plate #
if(year < 10 || year > 25)
{
valid = 0; // return invalid
}
if(halfYear != 1 && halfYear != 2)
{
valid = 0; // return invalid
}
if(County != 'C' && County != 'D' && County != 'G' && County != 'L' && County != 'T' && County != 'W'
&& County != 'c' && County != 'd' && County != 'g' && County != 'l' && County != 't' && County != 'w')
// Run acceptable county #s
{
valid = 0; // return invalid
}
if(Sequence >= 1000000 || Sequence < 1) // range of sequences
{
valid = 0; // return invalid
}
return valid; // Return valid
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgaXJpc2hMaWNlbnNlUGxhdGVWYWxpZGF0b3IoaW50IHllYXIsIGludCBoYWxmWWVhciwgY2hhciBDb3VudHksIGludCBTZXF1ZW5jZSk7CgppbnQgbWFpbih2b2lkKSB7CglpbnQgeWVhciA9IDEyOwkJCQk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