Serial.println only printing out 0's

i am new to arduino and do not understand why this code below only prints out zeroes. Any help is appreciated :slight_smile:
int x = 0;
int y= 0;
void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:
x = 5;
y = x/10;
Serial.println(y);
}

You are using integers. 5/10 is zero in integer arithmetic. try making them floats instead.

Hi, @csdivad
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

Is that your complete code, where is the Serial.begin() line?

Ditto as @wildbill has said.

Tom... :smiley: :+1: :coffee: :australia:

Please edit your post, select all code and click the </> button to apply code tags. Next save your post.
Code tags will preserve formatting, prevent odd characters showing (not in your case) and makes it easier to read an copy.

Thanks.

x=0.5 which cannot be an integer [int] and must be a [float] for decimals.

How does it work without Serial.begin(9600); in setup?

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