# Arduino Arithmetic Issue

In my program code, I am performing below given arithmetic operation but I am getting the wrong answer every time.

int A; double B;

A= (2400 - (((180-B)/2)+(B-90))*10);

For Example: If, B = 162.98

then I am getting A = 1665 whereas I should get 1585.

What can be the issue in this calculation.

Thank you,

Regards, Nirav

Please give the full program. Don't forget to put it in a code box!

Weedpharma

Using

``````void setup() {
Serial.begin(115200);
double B = 162.98;
int A = (2400 - (((180-B)/2)+(B-90))*10);
Serial.println(A);
}

void loop() {

}
``````

I get 1585 so you must be doing something wrong but without seeing your actual code nobody can help.

What can be the issue in this calculation.

Please post a Minimal, Complete, and Verifiable example.

Read this before posting a programming question

How to use this forum

1585 here too.

By the way :

``````int A = (2400 - (((180-B)/2)+(B-90))*10);
= 2400 - (90 - B/2 + B - 90) * 10;
= 2400 - (B/2) * 10;
= 2400 - B*5;
``````