Getting max value of an integer

Hey there,

I'm making a breathanalyzer with Arduino and I'd like to print the highest value from MQ3 alcohol sensor when someone blowed on the sensor. All my attempts failed so far. Could any of you point me to the right way plz?

The max() macro/function?
int maxval = max(val1, max(val2, max(val3, max(val4, val5))));

Apparently the Commonwealth of Massachussetts can't get it right either!
http://www.boston.com/news/local/massachusetts/2015/04/22/mass-das-suspend-breath-test-evidence-will-drunk-drivers-get-off/BvvkHVjN5ej6fqjV3l7HAP/story.html

KeithRB:
The max() macro/function?
int maxval = max(val1, max(val2, max(val3, max(val4, val5))));

There aren't multiple integers. There's only one integer and I want to get the highest value it has ever reached.

There aren't multiple integers.

Two is "multiple"

AWOL:
Two is "multiple"

In case I wasn't clear.

In my code there's just one integer and it's called "alcohol". I get it using:

alcohol = analogRead(A2);

And I need a way to get the highest value of it in any time. But Max function require me to use more than one integers.

In case I wasn't clear, there's the current value and the current highest value.
That's two values.

AWOL:
In case I wasn't clear, there's the current value and the current highest value.
That's two values.

Could you elaborate please? I don't get it.

alcohol = analogRead(A2);

There's the current value.

int currentMax = -1;

And there's the current highest value.

AWOL:

alcohol = analogRead(A2);

There's the current value.

int currentMax = -1;

And there's the current highest value.

And where does the max function come into play here?

There's the current value, and there's the current highest value.

If the current value is higher than the current highest value, then the current highest value is set to the current value.

That's where the max macro/function comes in.
Or you could just use an if.

I assume your current value is shown in a loop. If so, you simply need to compare your current value with a variable that stores the max value.

In psuedocode:

int maxval = -1

loop:
read current value.
display current value.
maxval = max(maxval, currentval)
display maxval

goto loop

You probably also need some way to reset maxvalue.

I'd just initialize Max to zero, and then in a loop:

alcohol = analogRead(A2);

if (alcohol > Max)
    Max = alcohol;

As a general rule you need to be a little careful with that... A glitch in the analog signal or "outlier" could cause an error.

But the maxval keeps adjusting itself to the current value. I want it to capture the highest value and show it all the time and only update itself when the sensor output exceeds that maximum.

Right now, if the alcohol integer drops below to the maximum value, the maxval also drops.

edit: nvm, i solved it.

Right now, if the alcohol integer drops below to the maximum value, the maxval also drops.

Then you're doing wrong, but until you post your code, that's all we're going to be able to say.