# [Solved] Weird problem can somebody explain please?

A couple of nights ago on another thread http://forum.arduino.cc/index.php?topic=289183.msg2026221#msg2026221, Paul__B was helping solve a problem.

Now the last post on that thread was me asking if someone could tell me what this :-

``````((total+)/10)
``````

was.

Now it has just become more confusing, when Paul posted his code

``````double R1[4] = {
8000.00, 4000.00, 2000.00, 1000.00};
double R2 = 90.00;
int total;
//int V = 5;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
int s1, s2, s3, s4;
double effective;
for (int n = 0; n < 16; n++) {
effective = 0.00;
s4 = (n & 0x08 ? 1 : 0);
Serial.print(s4);
Serial.print(" ");
s3 = (n & 0x04 ? 1 : 0);
Serial.print(s3);
Serial.print(" ");
s2 = (n & 0x02 ? 1 : 0);
Serial.print(s2);
Serial.print(" ");
s1 = (n & 0x01 ? 1 : 0);
Serial.print(s1);
Serial.print(" ");
if (s1) effective = effective + (1 / R1[0]);
if (s2) effective = effective + (1 / R1[1]);
if (s3) effective = effective + (1 / R1[2]);
if (s4) effective = effective + (1 / R1[3]);
effective = (1 / effective);
//    Serial.print(effective);
//    Serial.print(" ");
total = (1023-((effective / (R2 + effective)) * 1024));
Serial.print(total);
Serial.print("   ");
Serial.print((total+)/10); // Note "linearising" tweak
Serial.println(" ");
}
}

void loop() {
// put your main code here, to run repeatedly:

}
``````

It compiled and ran without error, now I am trying to compile again, and I get an error. I have tried this on IDE 1.5.7 IDE 1.6.0 and IDE 1.0.6 all give

sketch_jan02a.ino: In function ‘void setup()’:
sketch_jan02a.ino:36:26: error: expected primary-expression before ‘)’ token

I even tried a restart of my computer, no different.

Can ANYBODY tell me what that function is… and why it is not now working for me.

Thanks,

Graham

According to that error message, it is in line 36.

I have never seen ( total+ ) / 10 in my whole life. As far as I know it is nonsense.

((total+)/10) is not a valid expression. Either put something after the "+", or perhaps it is meant to be "++"?

Regards,
Ray L.

I appreciate what you are saying, and I am very well aware of the error I am receiving, but did you read all of my original post? That code compiled and ran when I tried it 2 days ago!!!

So can I reiterate.... What does that function do, and why is not working for me now?

Thanks,

Graham

It's the total+ that is causing the problem

Mark

ghlawrence2000:
I appreciate what you are saying, and I am very well aware of the error I am receiving, but did you read all of my original post? That code compiled and ran when I tried it 2 days ago!!!

So can I reiterate.... What does that function do, and why is not working for me now?

Thanks,

Graham

I can't explain what I can't see. What I can tell you for certain is that the code, as it is here, absolutely did NOT compile. That line is not valid c syntax.

Regards,
Ray L.

A couple of nights ago on another thread http://forum.arduino.cc/index.php?topic=289183.msg2026221#msg2026221, Paul__B was helping solve a problem.

There are two sketches in that thread one with the total+ construct and one without,
only one of them compiles..

I don't know what that code does. Is it code for the Arduino Due, or the normal Uno/Nano/Micro boards ?

The only way that code compiled is if you included a library that provided an operator definition for a post-fix +, which is pretty unlikely.

The is C++, not C, remember, so operator syntax can be updated.

Ok, so lets take this from a different angle…

If we just use (total/10) the result is :-

``````0 0 0 0 0   0
0 0 0 1 10   1
0 0 1 0 21   2
0 0 1 1 32   3
0 1 0 0 43   4
0 1 0 1 53   5
0 1 1 0 63   6
0 1 1 1 73   7
1 0 0 0 83   8
1 0 0 1 93   9
1 0 1 0 102   10
1 0 1 1 111   11
1 1 0 0 120   12
1 1 0 1 129   12
1 1 1 0 138   13
1 1 1 1 146   14
``````

Whereas what is actually wanted is :-

``````0 0 0 0 0   0
0 0 0 1 10   1
0 0 1 0 21   2
0 0 1 1 32   3
0 1 0 0 43   4
0 1 0 1 53   5
0 1 1 0 63   6
0 1 1 1 73   7
1 0 0 0 83   8
1 0 0 1 93   9
1 0 1 0 102   10
1 0 1 1 111   11
1 1 0 0 120   12
1 1 0 1 129   13
1 1 1 0 138   14
1 1 1 1 146   15
``````

This was the result of ((total+)/10). I really cannot explain why it did work… So assume, I imagined it… how do we linearise the list shown… (using code that works)?

Thanks,

Graham

Edit: Ok so I must have dreamed it worked… I see if we use ((total+5)/10) That works and is actually syntax I understand