Highest Value

I am trying to use robotc to determine the highest of eight input analog values. Right now, I am using a program that will compare the averages of all the values (attached is a picture of some of the program). However, if two value are high enough, they can both be higher than the average. Is there a way to determine a single highest value?
Untitled.jpg

It’s difficult for me to see the code in the image provided; could you post it on the forum directly, using the

 tags possibly? This will make it much easier for me to debug the code.

That being said, you may be able to do a quick hard-coded solution for this by looping through each element of an array (which holds the values of each of the 8 analog sensor ports) and checking to see if the current analog port's value is higher than the previous ports' value:


[CODE]

task main()
{
	//First, create an array that stores all of your analog input values
	int myArray[8] = {
		SensorValue[in1],
		SensorValue[in2],
		SensorValue[in3],
		SensorValue[in4],
		SensorValue[in5],
		SensorValue[in6],
		SensorValue[in7],
		SensorValue[in8]};

	//Next, create a temporary variable to store the highest Sensor Value
	int foo = 0;

	//Create a for loop iterates through element of myArray (zero indexed)
	for (int x = 0; x < 8; x++)
	{
		if(myArray[x] > foo)
		{
			foo = myArray[x];	
		}
	}

//At the end of the loop, foo will contain the highest sensor value.
}
[/CODE]

task main()
{

		value_45 = 0;
		value_90 = 0;
		value_135 = 0;
		value_180 = 0;
		value_225 = 0;
		value_270 = 0;
		value_315 = 0;
		value_360 = 0;


		startMotor(cmotor,18.5);

		untilEncoderCounts(45, position);
		value_45 = (SensorValue(input));

		untilEncoderCounts(45, position);
		value_90 = (SensorValue(input));

		untilEncoderCounts(45, position);
		value_135 = (SensorValue(input));

		untilEncoderCounts(45, position);
		value_180 = (SensorValue(input));

		untilEncoderCounts(45, position);
		value_225 = (SensorValue(input));

		untilEncoderCounts(45, position);
		value_270 = (SensorValue(input));

		untilEncoderCounts(45, position);
		value_315 = (SensorValue(input));

		untilEncoderCounts(45, position);
		value_360 = (SensorValue(input));

		stopMotor(cmotor);

		wait(1);

		direction();


	}

void direction()
{
	turnLEDOff(led45);
	turnLEDOff(led90);
	turnLEDOff(led135);
	turnLEDOff(led180);
	turnLEDOff(led225);
	turnLEDOff(led270);
	turnLEDOff(led315);
	turnLEDOff(led360);

	if	 ( (value_45) > ( (value_90 + value_135 + value_180 + value_225 + value_270 + value_315 + value_360) / 7) )
	{
		turnLEDOn(led45);
	}
	else
	{
		turnLEDOff(led45);
	}

	if ( (value_90) > ( (value_45 + value_135 + value_180 + value_225 + value_270 + value_315 + value_360) / 7) )
	{
		turnLEDOn(led90);
	}
	else
	{
		turnLEDOff(led90);
	}

	if ( (value_135) > ( (value_90 + value_45 + value_180 + value_225 + value_270 + value_315 + value_360) / 7) )
	{
		turnLEDOn(led135);
	}
	else
	{
		turnLEDOff(led135);
	}

	if ( (value_180) > ( (value_90 + value_135 + value_45 + value_225 + value_270 + value_315 + value_360) / 7) )
	{
		turnLEDOn(led180);
	}
	else
	{
		turnLEDOff(led180);
	}

	if ( (value_225) > ( (value_90 + value_135 + value_180 + value_45 + value_270 + value_315 + value_360) / 7) )
	{
		turnLEDOn(led225);
	}
	else
	{
		turnLEDOff(led225);
	}

	if ( (value_270) > ( (value_90 + value_135 + value_180 + value_225 + value_45 + value_315 + value_360) / 7) )
	{
		turnLEDOn(led270);
	}
	else
	{
		turnLEDOff(led270);
	}

	if ( (value_315) > ( (value_90 + value_135 + value_180 + value_225 + value_270 + value_45 + value_360) / 7) )
	{
		turnLEDOn(led315);
	}
	else
	{
		turnLEDOff(led315);
	}

	if ( (value_360) > ( (value_90 + value_135 + value_180 + value_225 + value_270 + value_315 + value_45) / 7) )
	{
		turnLEDOn(led360);
	}
	else
	{
		turnLEDOff(led360);
	}



}