how to i store up my multiple outputs into one variable?

First off all, I'm sorry to ask a this simple question, am new to programming,thanks.

void loop() {


  val2 = analogRead(A2);
  v1 = val *(5.0/1023.0);
  delay(2000);

  val = analogRead(A4);
  v2 = val2 *(5.0/1023.0); 
  delay(2000);

The problem .
float z;
z = (v1,v2);
Serial.println(z);

all I get to print is the last(v2), nothing printed on v1.

}

Well instead of printing them one by one? How will i be able to print them in oneline? like storing up my outputs in one variable..

If you may, is there ways to shortened the codes instead of copying the codes for every installed led.

Well instead of printing them one by one? How will i be able to print them in oneline?

Why does it matter?

Have you considered arrays?

float z[2] = {v1, v2};
for (int i = 0; i < 2; i++)
{
  Serial.println(z[i]);
}

AWOL:
Why does it matter?

Have you considered arrays?

Was planning to use the outputs in an nested if program, instead of putting up all of it the conditions just wondered if i can make them into one variable and compare the value for the conditions

well i have tried arrays, but it gives me alot of errors.. plus its not a good a practice to see redundant codes right?

Another Q:

if (z[] = someValue)
{
Serial.println("ERROR");
}

Just wondering if this is the right syntax for the z to be use in if else statement?

pjaypabs:
Was planning to use the outputs in an nested if program, instead of putting up all of it the conditions just wondered if i can make them into one variable and compare the value for the conditions
<…>

@pjaypabs: Welcome, I don’t think we have run into each other before… but, I’m off in 32-bit land mostly these days.

In C/C++/Arduino the descriptive term is variable type: Boolean, integer, string, float, String … that sort of thing.
When you read a digital pin, your results are either High or Low (Boolean).
When you read an analog pin, your results are an unsigned integer (However often seen in Arduino code as a int)

While this example was meant to print over the USB via HID, you can at least see how various values can be read and output. You might as well read this article to understand the syntax that I am using to print.

An array element (name) must always have an index… such as myArray[2] which is the third element.

IT IS A VERY UNWISE practice to attempt to compare a float value with an int… very bad. Floats are IEEE compliant structures and what you really need to do is to compare them using < (less than) or > (greater than).

Good luck,

Ray
Ray’s Projects

if (z[] = someValue)In C, = is always an assignment, never a comparison.