output for division of numbers program

I am getting the output for below program as "Inf" when i am giving y=0. i was expecting "y value should not be zero". how to correct it.

myfunc<-function(){
a=as.numeric(readline(prompt="Enter the value of x:"))
b=as.numeric(readline(prompt="Enter the value of y:"))
if(b=0){print("y value should not be zero")}
else{print(a/b)}
}
myfunc()

To test for equality, use the == operator.

myfunc<-function(){
  a=as.numeric(readline(prompt="Enter the value of x:"))
  b=as.numeric(readline(prompt="Enter the value of y:"))
  if(b==0){
    print("y value should not be zero")
  } else {print(a/b)}
}
1 Like

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.

God! my bad. Thanks FJCC