i have been asked to "Write a function with one argument, L, such that, if L is a number, then it is
doubled and returned, otherwise it is returned unchanged" The problem iwhenever i run the function and say type in something other than a number it does not return the input exepct return an error i want the function to return the input.it does return the double of the number but i also want it to retun whatever i put as the input.here is my code
This looks like a school assignment, but anyway...
Apart from missing parentheses at the end, there are probably some missing in the (missing) application of the number? predicate. Look at cond[1] documentation - the mistake should be obvious. Also remember that if no cond-clause matches and produces a result, the result is void - an else clause is what you are probably looking for. But right now that is not the error you see in your code. Also the error that's produced is fairly self-explanatory:
> (L "a")
; *: contract violation
; expected: number?
; given: "a"
; [,bt for context]
Anything you pass to your procedure gets passed on as second argument of * procedure.
Is there any reason you are using cond and not if for this one?
im still confused the number? checks to see if the input is a number however i want to ignore it if its not and return the input such as S can you give a little more help
Hi @osman44 , allow me to offer an additional suggestion: change DrRacket to use the "Beginning Student Language" and run your program again -- if you do this, DrRacket will tell you exactly what the problem is.