compound addition trouble

getting an error somewhere in my compound additions. being very new to programming i am having trouble finding the fault

int x = 0;
int y = 1;
int t = 2;
int r = 3;
void setup() {
  pinMode(A0, INPUT);
  pinMode(A1, INPUT); 
  pinMode(2, OUTPUT);  
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(9, 0);  // start with the "dot" off
  
}
void loop() {
if (analogRead(1) < 20) (x += y);  // if only the low sensor is activated +1 is added to 'x'
if (analogRead(2) < 20) (x += t);  // middle sensor +2
if (analogRead(3) < 20) (x += r);// top sensor +3
}
 (x)+= x + y));
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);}// write '1'

anywhere i could get some help would be great

(x)+= x + y));

That needs work.

Also, none of this:

 (x)+= x + y));
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);}// write '1'

Is inside any function.

what should the funcion be for the digital output piece and should it be in the loop or setup?

Perhaps you should be more specific. What error and where? You sketch gets a number of compiler errors, mostly because you put a '}' after the third analogRead() line. That ends the loop() function and the code after that is outside any function.

The line

 (x)+= x + y));

has an extra close-paren and doesn't make much sense.

trvslamm:
what should the funcion be for the digital output piece and should it be in the loop or setup?

I don't know, what are you trying to do with it?

when each sensor is below threshold it will add +1 +2 respectivly then output the info as digitalwrite to binary 1=high 0=low for 7 segment display LED's

now i have the first addition compiled but the the addition for 'write 2' will not

(x)+= x + y;
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);}// write '1'
 
 (x)+ x + t;
 digitalWrite(2, 1);
 digitalWrite(3, 1);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 0);
 digitalWrite(8, 1)};// write '2'

whats wrong with this?

(x)+ x + t;

because you are not assigning the result to anything.

Think about it, if you add any numbers together, you have to save the result somewhere, even if it is just a temporary variable.

Are you simply trying to add t to x and save it in x? similarly are you trying to add y to x and save the result in x?

If so you would use compound operators like:

x += y;
//or
x += t;

which is a short way of writing:

x = x + y;
//or
x = x + t;

You can use compound operators on literals as well:

x += 3;
//is the same as:
x = x + 3;

x += 1;
//is the same as:
x = x + 1
//this on is unique in that it can be written as:
x++;

x -= 1;
//is the same as:
x = x - 1
//this one is also unique in that it can be written as:
x--;

There are other operations as well:

x *= 2;
//is the same as:
x = x * 2;

x /= 2;
//is the same as:
x = x / 2;

x %= 2; 
//is the same as:
x = x % 2;

x >>= 2;
//is the same as:
x = x >> 2;

x <<= 2;
//is the same as:
x = x << 2;

//I could go on, but I am going to stop there. There are also:
// &=
// |=
// ^=
//And on some compilers (not sure about gcc):
//x \= 2; which is the same as: x = 2 / x

trvslamm:
whats wrong with this?

(x)+ x + t;

It's outside any function because of the '}' in

 digitalWrite(8, 0);}// write '1'

the code will compile now but when i upload it to arduino it starts at '4' on my digit display and will not register the additions as the analog thresholds are breached

{

 if (x += y);
 digitalWrite(2, 1);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);}// write '1'
 {
   
 if (x)+ x + t;
 digitalWrite(2, 1);
 digitalWrite(3, 1);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);}// write '2'

I assume it is somewhere in this part of the code (the binary is different due to a different digit display)

[code] if (x += y);

This line does nothing but add 1 to x. The only statement controlled by this IF is the ";" at the end of the line, called the NULL Statement.

[/code] if (x)+ x + t; {/code]

This line does even less. It is equivalent of ";" because the statement "+x+t" doesn't do anything.

You seem to be thinking that '+' is going to cause some kind of comparison. It doesn't. Perhaps you should write out in english what you want the code to do.

When A0 is less than 20 add 1 to the cumulative total on the digit display. if A1 < 20 add 2 to the cumulative total on the digit display. if A2 < 20 add 3 to the cumulative total. to count threshold breaches up to 9.

trvslamm:
When A0 is less than 20 add 1 to the cumulative total on the digit display. if A1 < 20 add 2 to the cumulative total on the digit display. if A2 < 20 add 3 to the cumulative total. to count threshold breaches up to 9.

That's about the only thing that's obvious from your code. I infer that you have some sensor and a 7 segment led digit that you want to have count up according to those rules. Is that correct?

When it reaches 9 what happens then?

In your description you call it cumulative total but in your code you call it x (near as I can tell). Why not call it cumulativeTotal? Using more descriptive variable names is very helpful.

The other guys have really pointed out everything that's wrong already. Slow down, dig in and work on understanding what they are saying. Use the arduino language reference page.

Here's your code again. It compiles and may even run. I didn't try. I think it will display a 1, x likely overflows in very short order but you probably wouldn't notice.

int x = 0;
int y = 1;
int t = 2;
int r = 3;

void setup() {
  pinMode(A0, INPUT);
  pinMode(A1, INPUT); 
  pinMode(2, OUTPUT);  
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(9, 0);  // start with the "dot" off

}

void loop() {
  if (analogRead(1) < 20) (x += y);  // if only the low sensor is activated +1 is added to 'x'
  if (analogRead(2) < 20) (x += t);  // middle sensor +2
  if (analogRead(3) < 20) (x += r);// top sensor +3

  digitalWrite(2, 0);
  digitalWrite(3, 1);
  digitalWrite(4, 1);
  digitalWrite(5, 0);
  digitalWrite(6, 0);
  digitalWrite(7, 0);
  digitalWrite(8, 0);// write '1'
}