Heya! I'm trying to make a calculator for a school project, but I've got a problem. The code I've got for the display requires an array of integers, but the code for the calculations returns a long. Here's the code I've got right now, but for some reason it breaks after a few cycles, returning negative numbers for no discernible reason, making it so that input_array = { -2, -3, 0, -1, 3, 0, 0, 8 }. I've included the important parts of the code below, if anything else is important, I can give that as well.
I've got two important questions:
Why does this break?
How do I make it so it doesn't?
Also, if there's a better way to cast this, that would be nice to know as well!
// Display
long input_number;
int input_array[8];
float result;
void setup() {
}
void loop() {
if (!solved) {
// Result is set based on calculations via a keypad
input_number = abs(round(result));
solved = true;
Serial.println(input_number);
// Preparing the display
if (!is_error) {
for (i = 0; i < 8; i++) {
input_array[i] = (int(input_number / pow(10, i))) % 10;
// It breaks here
}
}
}
// Display based on input_array
}