Backwards Question Mark - Baud Rate 9600 - Removing Libraries Fixes Problem

The following code is a function from a sketch I am working on. If I take the libraries out of the code everything works fine, but if I leave any library in I get a backwards question mark in serial. Research told me that the backwards question mark is usually caused by non matching baud rates...I have made sure my baud rates are the same.

In the code below I have included just one of the libraries I am using in the full sketch since the error happens with any library that I have used. The assignNumber function is meant to split numberOne and numberTwo into 4 numbers and store each element in splitArray. In the example I want to split 43 and 8 into 4, 3, 0, and 8 and store them in splitArray[0], splitArray[1], splitArray[2], and splitArray[3] respectively.

I am open to suggestions for better ways to do this. But mostly I would like to know how to fix the problem or know what is causing the problem. Thank you in advance.

#include <SPI.h>

int numberOne = 43;
int numberTwo = 8;
int numberArray[] = {numberOne, numberTwo};
int splitArray[3];

void setup() {
Serial.begin(9600);
assignNumber();
}
void loop() {

}
void assignNumber() {
int x;

//divides numberOne by 10 to get the first digit of numberOne
//first digit of numberOne in splitArray
splitArray[0] = numberArray[0] / 10;

//stores numberOne in x so it can be used in the loop
x = numberArray[0];
//subtracts 10 from x until x is less then 9
//to get the second digit of numberOne
while (x > 9) {
x -= 10;
}
//second digit of numberOne in splitArray
splitArray[1] = x;

//divides numberTwo by 10 to get the first digit of numberOne
//first digit of numberTwo in splitArray
splitArray[2] = numberArray[1] / 10;

//stores numberTwo in x so it can be used in the loop
x = numberArray[1];

//subtracts 10 from x until x is less then 9
//to get the second digit of numberTwo
while (numberArray[1] > 9) {
x -= 10;
}
//second digit of numberTwo in splitArray
splitArray[3] = x;

//prints each element of splitArray for testing
//should print
//4
//3
//0
//8
Serial.println(splitArray[0]);
Serial.println(splitArray[1]);
Serial.println(splitArray[2]);
Serial.println(splitArray[3]);
}

I am open to suggestions for better ways to do this.

may be posting with code tags and reading the forum rules?

Side note, this index does not exist splitArray[3] = x;

You also seem unaware of the modulo operator....

 x = x % 10; //get the remainder after dividing by 10

Thank you J-M-L that solved it. I figured it was something simple.

And not pcbbc not unaware, just forgot...it's been a while since I learned programming, but thank you for the reminder.

This worked for me:

byte numberArray[] = {43, 8};
int splitArray[4];


void setup()
{
  Serial.begin(115200);
  assignNumber();
}


void loop() {}


void assignNumber()
{
  splitArray[0] = numberArray[0] / 10;
  splitArray[1] = numberArray[0] % 10;
  splitArray[2] = numberArray[1] / 10;
  splitArray[3] = numberArray[1] % 10;


  //prints each element of splitArray for testing
  //should print
  //4
  //3
  //0
  //8
  Serial.println(splitArray[0]);
  Serial.println(splitArray[1]);
  Serial.println(splitArray[2]);
  Serial.println(splitArray[3]);
}