Hello, sorry if this is a bit of a noob question, relatively new to c++ and the arduino language.
Basically, I'm trying to convert the string amount from the array infoArray into an int in order to run the for loop below. (if I don't convert to int, it tells me that i isn't defined. I think that's the issue?) I know that infoArray is always a one digit number as a string.
I've tried the function toInt() but it gives me the error below:
request for member 'toInt' in 'amount', which is of non-class type 'int'
Hi. So regarding the entire code, I'm on vacation and don't have it at the moment, but everything else worked fine, I've only started running into issues with this function. A basic run through of the program would be the arduino receives a string through serial, and then takes each character and puts them into an array. Then it would perform certain actions based on what numbers/characters are where.
For your second post, yes, I realized that the array wasn't a string and an ascii char instead, but when I tried yours and chrisnightley's solutions, the program returned that i in the for loop wasn't defined, which tells me that amount wasn't actually converted to an int. (I think?)
Subtract '0'(character) from '0'(character) to get 0(number).
Subtract '0'(character) from '1'(character) to get 1(number).
Subtract '0'(character) from '2'(character) to get 2(number).
Subtract '0'(character) from '3'(character) to get 3(number).
... to 9
My second solution was exactly the same as @chrisknightley
So what ever was wrong it is not what I told you to do. It was probably that you had not implemented it correctly, I just gave you and example using variables that reflected what you needed to do.
If you had not declared ’amount’ as a variable previously in your code and used i as the loop variable then yes you will get an error saying the variable i was not declared.