Hello everyone, can someone help me with this question?
Why is the result 3 and not 3.333?
What am I doing wrong?
I have tried both ways
int x = 10;
int y = 3;
float respaldo = (x / y);
Serial.println(respaldo, 3);
int x = 10;
int y = 3;
float respaldo = (float)(x / y);
Serial.println(respaldo, 3);
You are instructing the computer to do an integer divide and convert the result to float. The answer is correct.
Try this
float respaldo = (float) x / y;
Diego_L
February 10, 2024, 4:15pm
4
float respaldo = (float) x / y;
This works fine, thanks!
1. Do you know the meaning/value of (float) x ? (Given: int x = 10; )
2. Without uploading the following codes in the Arduino UNO, can you tell what will be the value of y --?
float x = 10.93;
int y = (int) x;
Diego_L
February 10, 2024, 5:08pm
7
"y" will be 10, because "y" is a integer
2 Likes
y will be 10 because x was casted to int....
system
Closed
August 8, 2024, 6:10pm
9
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.