I was going through an R Function exercise, in this exercise we are required to create a function called bar_count that returns the least amount of aluminum bars required to fulfill an order, there are only two types of bars, 5kg bars and 1kg bars. The function should return F if the order has decimal it can only be exact numbers.
Here is what I came up with:
bar_count <- function(kg){
  num.of.five <- 0
  num.of.one <- 0
  five.kg <- kg/5
  if (kg%%5 == 0){
    num.of.five <-num.of.five + five.kg
  } else if(kg%%5 != trunc(kg%%5)){
    return(F)
  }else if (kg%%5 >= 1) {
    num.of.five <- num.of.five  + trunc(five.kg)
    num.of.one <- num.of.one + ((kg%%5))
  }
num.of.bars <- num.of.five + num.of.one
return (num.of.bars)
return(paste('qty of 5kg bars is:', num.of.five))
return(paste('qty of 1kg bars is:',num.of.one))
}
The problem I am having is with the two last commands where I ask R to return(paste()) the quantity of aluminum bars for the 5kg lot and the 1 kg lot, however it does not return any of those two,it only returns the total amount, I have tried with print() but it hasn't work either.
Thank you for taking the time to answer
 
     
    