Invalid Operation and Incompatible types when attempting to save data to an aray

Yet again, arrays are giving me trouble. These errors happen in 2 different places in my code: once when following an equation, and the other when returning an array from a function:

1. The Math Error:

In order to split up a number into its digits mathematically, I've engineered an equation that theoretically should return each digit of the number separately depending on the value of j:

int currentDigits[len(inputNum)];
    for (int j = 0; j > len(inputNum); j++) {
    currentDigits[j] = floor(inputNum / pow(10, len(inputNum) - (j + 1))) % 10; // spits out each digit of the number from left to right
    }

In english, the equation would look like this:

Equation Photo

I only included a picture in case you didn't feel like leaving the site to learn how this equation works, so if you want to see it in better quality, the Desmos link is here.

Anyway, the moral of the story here is that the equation uses the %, and because of it, I get a weird error:

/tmp/2412396064/ALAAARRMM/ALAAARRMM.ino: In function 'int getIRNumInput(String*, int*, int*, String)':

/tmp/2412396064/ALAAARRMM/ALAAARRMM.ino:595:82: error: invalid operands of types 'double' and 'int' to binary 'operator%'

currentDigits[j] = (inputNum[i] / pow(10, len(inputNum[i]) - (j + 1))) % 10; // spits out each digit of the number from left to right

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~

The confusing part about all of this is that this doesn't even use doubles! floor() should have converted the decimal into an integer long before it hits the modulus sign! Absolutely no idea what's going on there

2. The Function returning error:

For this one, I have a function returning a list of values to another list that populates takes the values from the return and populates itself with them. Take a look:

AlarmID_t getAlarms(String filter = "None") {
  int totalAlarms = Alarm.count();
  AlarmID_t allAlarms[Alarm.count()]; //<-- Array #1
  for (byte i; i > totalAlarms; i++) {
    allAlarms[i] = allAlarmIDs[i];
  }
  if (filter.equalsIgnoreCase("None")) {
    return allAlarms;
  }
}
AlarmID_t getIRAlarmInput(String prompt, String noAlarmsErrorPrompt = "You have no timers or alarms that can be used with this command!") {
  if (Alarm.count() == 0) {
    fail(noAlarmsErrorPrompt);
    return -1;
  }
  AlarmID_t currentAlarms[Alarm.count()]; //<-- Array #2
  currentAlarms = getAlarms();
...

For context, AlarmID_t is basically an identifier for active alarms. If you need to check/change an alarm for any reason, you use AlarmID_t to specify which tier/alarm you want to look into. There can only be a max of 6 alarms due to hardware limitations, so the identifiers are just stored as single character.

Going back to the functions, you can see that the 2 arrays are the exact same size and Data Type. However, when I go to run this, I get the following error:

/tmp/3222019146/ALAAARRMM/ALAAARRMM.ino: In function 'AlarmID_t getIRAlarmInput(String, String, String, String)':
/tmp/3222019146/ALAAARRMM/ALAAARRMM.ino:925:29: error: incompatible types in assignment of 'AlarmID_t {aka unsigned char}' to 'AlarmID_t [(<anonymous> + 1)] {aka unsigned char [(<anonymous> + 1)]}'
currentAlarms = getAlarms();
^

The error message message makes one of them look like a list, while the other is a normal Data Type even though they are both the exact same. Again, no clue what's happening here

Any clue what I did wrong in both instances? Arrays are a pain to deal with...

Your snippets are useless. Post a small, complete code that demonstrates the problem.

If you get compiler errors, post them verbatim, not your paraphrased version of what you think they are.

If the errors are run-time, post the results you get and those that you expect.

amusing. No declaration in sight, so just what is inputNum, a float, int long, array, ????
Agree with @gfvalvo you need to provide a LOT more context.

Is this thread really not a followon from

?

The compiler errors are there verbatim, that's just all the info I got. I can post the full traceback if you want, but it's a traceback for a file that's 1000+ lines long with a lot of unreated code in there. I trimmed it so it only showed the traceback messages of the code that's relavent to the question I'm asking

InputNum is a number (integer), and len() returns the amount of digits in said number by using logorithims. If you want context on the equation and its components while I update the example code itself to give more context, I already gave a link and photo of a comprehensive breakdown of what each segment of the equation is and how it works if that's what you're insinuating. I wouldn't want to hurl a giant equation on you and expect for you guys to figure it out yourselves lol

It is, but the forum etiquette I'm used to indicates to make a new thread when you're talking about diffferent topics. Unless I'm stupid, the questions asked here are different from the ones asked there

Huh, didn't know that. But since the pow() is inside the floor() function, it would turn it into an integer by the time I got to the modulus part?

Welp, that explains that...

Yah, so tell me. With an array of ints declared to, let's say, 5, and j iterating from 0 to , oh, wait a minute, j will be 0 first time through, which isn't > len, so abort.
`for(int j= 0; j< len(); j++)

might work better, no?`
YMMV.

True, but the for loop isn't the part I need help on. Thanks for the catch, though.

So if you plug in something like floor(3/2), it would return 1.0 instead of just 1? I had no idea it worked like that. A little annoying, but I guess it kind of makes sense?

Ahh. And I thought this code did something you wanted help with. My bad.
!Mute!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.