Having trouble with syntax
in
Programming Questions
•
1 year ago
Hi guys, I'm trying to write a program to find and print the largest, middle, and smallest variable in order and I've become completely stumped with finding the middle variable. Would anyone mind taking a look and getting an outside view on it? Any help is appreciated :)
void setup(){
//Finds and prints the largest, smallest, and middle numbers
int w,x,y,largest,smallest,middle;
w=5;
x=3;
y=9;
//Finds the largest number
largest=w;
if(x>largest)
largest=x;
if(y>largest)
largest=y;
//Finds the smallest number
smallest=w;
if(x<smallest)
smallest=x;
if(y<smallest)
smallest=y;
//Finds the middle number
if (smallest<w && w<largest)
{ middle=w;}
else if (smallest<x && x<largest)
{ middle=x;}
else if(smallest<y && y<largest)
{ middle=y;}
else if(smallest<=w && w<=largest)
{ middle=w;}
else if(smallest<=x && x<=largest)
{ middle=x;}
else if(smallest<=y && y<=largest)
{ middle=y;}
//Prints the largest, middle, and smallest numbers in order
println(largest);
println(middle);
println(smallest);
}
1