Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- area = function(r){
- return(round((pi*r^2),2))
- }
- diameter = function(r){
- return (2*pi)
- }
- circumference = function(r){
- return (round((2*pi*r),2))
- }
- calCircle = function(){
- radius = as.numeric(readline("Enter value for radius (cm):"))
- message("Calculate:\n(A)rea\n(C)ircumference\n(D)iameter")
- option = readline("Option:")
- calculation = switch(option,A="Area",C="Circumference",D="Diameter","Error")
- result=switch(option,A=area(radius),C=circumference(radius),D=diameter(radius),"Error")
- if(result !="Error"){
- print(paste("The",calculation,"of the circle in cm is",result))
- }else{
- print("Invalid option")
- }
- }
- getRadius = function(){
- radius = as.numeric(readline("Enter value for radius (cm):"))
- return(radius)
- }
- getOption = function(){
- message("Calculate:\n(A)rea\n(C)ircumference\n(D)iameter")
- option = readline("Option:")
- return(option)
- }
- printoutput(calc,res){
- mainfunction = function(){
- radius=getRadius()
- option=getOption()
- calculation=switch(option,A="Area",C="Circumference",D="Diameter","Error")
- result=switch(option,A=area(radius),C=circumference(radius),D=diameter(radius),"Error")
- printoutput(calculation,result)}
- mainFunction()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement