[SOLVED] Splitting an int into equal parts

As the subject reads, I’m attempting to split an int into separate equal parts that are 2 digits wide (ie ExpDate1 to equal ‘12’ and ExpDate2 to equal ‘34’). I’m getting the error, “incompatible types in assignment of ‘unsigned int’ to ‘int’” and I don’t know how to correct this. I’ve tried changing ExpDate from int to char, volatile, unsigned. But nothing seems to give the output I’m looking for.

Can someone please explain what I’ve done wrong here?

int n1[2];
int n2[2];

int n = 1234;
Serial.println(n);

{
   unsigned int a[4] = { n };
   const unsigned int Base = 10;

    for (size_t i = 0; i < sizeof(a) / sizeof(*a); i++)
      {
         unsigned int divisor = Base;
         while (a[i] / divisor > divisor) divisor *= Base;

         n1 = (a[i] / divisor);
         n2 = (a[i] % divisor);
      }
         Serial.println(n1);
         Serial.println(n2);
}
   unsigned int a[4] = { n };

What’s that?

You sure are making it too hard:

int val = 1234;

void setup() {
  Serial.begin(9600);
  int val1 = val/100;
  int val2 = val%100;
  Serial.println(val1);
  Serial.println(val2);
}

void loop() {
}

Todd,

Sorry for the late reply. Had a personal issue come up and a stupid question came out. Couldn't concentrate the past few weeks from a screwed up med change and probably annoyed quite a few people. I appreciate the patience. And thanks for the reply you posted.

peasoup:
Todd,

Sorry for the late reply. Had a personal issue come up and a stupid question came out. Couldn't concentrate the past few weeks from a screwed up med change and probably annoyed quite a few people. I appreciate the patience. And thanks for the reply you posted.

No problem. Hope you are better. Been there done that...