numbers aren't adding up correctly with += or + operators. EX: "a = a + b"

so I purchased some new photoresistors from radioshack. RadioShack.com Official Site - America's Technology Store
I also have one of my own. I only assume it is the same kind of CdS photoresistor, as it looks the same.
I wanted to make sure they would read the light at the same levels, so I made a program to take care of that. (some of the 5-pack photoresistors look slightly different, with smaller or larger light-sensitive areas, or other minor differences.)

I use an Arduino Uno Rev3 board.

one end of a photoresistor has a wire leading to the analog input and a 10K OHM resistor leading to a wire which leads to the power source on the protoboard. (basically it is a voltage divider) The other end of the photoresistor leads to ground. All six of the photoresistors are each independently wired up in this way. Of course I also have a wire going from the arduno's 5v pin to the protoboard and another wire leading from the ground pin to the protoboard for the power and ground pins on the protoboard.

I also have the arduino plugged into a wall-wart just in case the power from the USB isn't enough to power the Arduino. (This is an issue I have experienced with previous computers in the past when the computers didn't use enough power to actually give the arduino enough power via usb to work.)

here is the code:

void setup()
{
Serial.begin(9600);
}
void loop()
{
int a0 = 0;
int a1 = 0;
int a2 = 0;
int a3 = 0;
int a4 = 0;
int a5 = 0;

int a0total = 0;
int a1total = 0;
int a2total = 0;
int a3total = 0;
int a4total = 0;
int a5total = 0;

a0 = analogRead(0);
Serial.print(a0);
a0total = a0total + a0;
Serial.print("|");
Serial.println(a0total);

a1 = analogRead(1);
Serial.print(a1);
a1total = a1total + a1;
Serial.print("|");
Serial.println(a1total);

a2 = analogRead(2);
Serial.print(a2);
a2total += a2total + a2;
Serial.print("|");
Serial.println(a2total);

a3 = analogRead(3);
Serial.print(a3);
a3total = a3total + a3;
Serial.print("|");
Serial.println(a3total);

a4 = analogRead(4);
Serial.print(a4);
a4total = a4total + a4;
Serial.print("|");
Serial.println(a4total);

a5 = analogRead(5);
Serial.print(a5);
a5total = a5total + a5;
Serial.print("|");
Serial.println(a5total);

Serial.println("~~~~~~~");
delay(3000);
}

Here is an example of the serial monitor's output for the first two iterations of the loop. It seems all six are detecting light correctly:
292|292
218|218
206|206
229|229
175|175
213|213

291|291
217|217
206|206
229|229
175|175
212|212

I use the second set of numbers in a line to add up the total of inputs for each iteration for each input. This way, over time, I can get a very clear picture of which photoresistor is more/less sensitive. (of course when I get this part working correctly I will divide the total for each input with the number of iterations.)

I know that in C++ I can even use
a5total += a5;
but that didn't work either, so I figured I would try something simpler. Alas, neither work. Whats my problem?

First alway post your code in code tags the # just above.

void loop()
{
  int a0 = 0;
  int a1 = 0;
  int a2 = 0;
  int a3 = 0;
  int a4 = 0;
  int a5 = 0;
  
  int a0total = 0;
  int a1total = 0;
  int a2total = 0;
  int a3total = 0;
  int a4total = 0;
  int a5total = 0;

Each time you enter loop a0total ect will be "created" and set to 0. Each time you get to the end of loop these loacal vars ar lost and so are there values. Give them global scope and look up scope

Mark

furthermore make the vars of the type long that has a bigger range

byte = 0..255
int = -32768..32767
long = -2e9 ... 2e9 (rounded :wink:

Even better for the totals use unsigned long. No need to waste half the range on -ve numbers you can't use.

Mark