Hi, can any one help me on how to write a pseudocode that returns the minimum of four numbers using the if---else conditions? So far i have successfully written a code for finding two and three numbers but I am stuck on the code for finding for four numbers. The code i have written looks like this

minimum4 <- function(a,b,c,d){

if(a>b)

if(b>c)

if(c>d){

d

}

else if(a>b)

if(b>c)

if(c<d){

c

}

else

if(a>b)

if(b<c)

if(b<d){

b

}

else {

a

}

}

but it returns a void answer when i am running it.

Searching through various forums has been unsuccessful since most people seem to use the min() function which works. But i wanted to learn how to write it personally.

Any assistance highly appreciate

you have syntax errors, you can''t follow and if() with if() directly without intervening symbols, you need to use curly braces to nest. I wonder about your working example for the case of 3, did you not face the same issue ?

Anyway, here is a version that avoids the need to heavily nest...

```
minimum4 <- function(a,b,c,d){
if(d<=a & d<=b & d<= c) d
else if(c<=a & c<=b & c<= d) c
else if(b<=a & b<=c & b<= d) b
else if(a<=b & a<=c & a<= d) a
}
```

I would also not use this code in my real work, rather, I would use min()

thank you. I have noted the highlighted mistake that i have been making. Thanks

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.