Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hi. third time posting this. have gotten help from two people but both sketches

ID: 3678529 • Letter: H

Question


hi. third time posting this. have gotten help from two people but both sketches show errors. this is for an arduino uno board. any help would be appreciated.

3. Start a new sketch and write codes to accomplish the following task: Give an array of 5 arbitrarily float numbers (e.g.. 70.11, -42, 1.0, -5.3, 1465). Use "for" loop and “if" statements to find themaxand the min numbers. Type '0' in Serial Monitor to display the min value in Serial Monitor, and type '9' to display the max number. Display a reminder message to user if any other number or character is being typed, such as "Unexpected input! Please type a number of 0 or 9:" Hint: 1. Define a float array to store the 5 numbers: float myNumbers = { }; 2. Define two float variables, such as "myMaxNum" and "myMinNum" to temporarily store the larger and the smaller numbers when compare any two numbers. You can first temporarily assume the first number is myMaxNum and myMinNum, then later compare it with the rest number to update myMaxNum or myMinNum when needed. MyMaxNum = myNumbersl0l: myMinNum myumbers[01 for lint is), i MyMaxNum) if (myNumbersti]

Explanation / Answer

float myNumbers[] ={70.11,-42,1.0,-5.3,1465};

float myMaxNum= myNumbers[0];

float myMinNum= myNumbers[0];

void setup()

{

Serial.begin(9600);

}

void loop()

{

for(int i=0;i<5;i++)

{

if(myNumbers[i] > myMaxnum)

myMaxNum= myNumbers[i];

if(myNumbers[i]< myMinNum)

myMinNum = myNumbers[i];

}

Serial.println("enter 0 for finding minimum number and 9 for maximum number");

if(Serial.avalable()>=0)

{

char userInput= Serial.read();

if(userInput =='0')

{

Serial.println("minimum number is:");

Serial.println(myMinNum);

}

else if( userInput == '9')

{

Serial.println("maximum number is:");

Serial.println(myMaxNum);

}

else

{

Serial.println("Unexpected input! Please type a number of 0 or 9 only!");

Serial.println(userInput); //you can drop this statement

userInput= Serial.read();

}

}

}