Hello everyone, its my first time in this forum, im new to arduino, i have an assignament due in 2 days, i need some help, im trying to make a program, using arrays and "for" cycles, where the user inserts 10 numbers using the monitor and then , gets shown back the odd numbers, ive done the code and im getting the error:
"invalid operands of types 'float' and 'int' to binary 'operator%'".
I've had 3, 1 hour 30 minutes classes about arduino and programing, most of the things i used for this code, i had to learn from the internet, the teacher gave each student a diffrent assignment, and just sort of told us to figure it out on our own, but it will be evaluated, so yeah i could really use the help.
Thanks in advance to anyone who takes the time to help me out.
Here is the code
float values[10];
int x = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for (x = 0; x < 10; x++) {
Serial.println( "insirt a value");
while (Serial.available() == 0) {}
if (Serial.available() > 0) {
values[x] = Serial.parseFloat();
}
}
Serial.println(" the odd numbers are ");
for (x = 0; x < 10; x++) {
if ( values[x] % 2 == 1 ) {
Serial.println( values[x] );
}
}
void loop() {
// put your main code here, to run repeatedly:
}
ive also tried values[x] & 1 == 1, gets me the error "invalid operands of types 'float' and 'bool' to binary 'operator&'"
AWOL:
The error messages are pretty self-explanatory.
The operators % and & are not defined for floating point datatypes.
Try integer datatypes instead.
I think i've fixed the code tags , thanks, but is there a way to make it so it works with float datatypes?