0
Two functions in a program (factorial and fibonacci) help
another one of my homework. it said Create a program with two choices to choose from:Fibonacci or Factorial. (which is Tail Recursion for Factorial and Fibonacci for Binary Recursion). so i bet i will create two functions on one program, and let the user input whether factorial or fibonacci. so how should i do it? i mean in simply choosing from those two programs i dont know. shoul i use else-if? switch case? like after choosing factorial, it will redirect to factorial and skip fibonacci. yknow you get what i mean
8 Answers
+ 5
Japheth ,
please do the homework by yourself. sololearn is not a coding service.
if you get stuck you can post your code here to get useful help from the community.
thanks for your understanding!
+ 2
I don't think it would really matter if you allow the user to choose using an "if/else" or a "switch". You would just need to link that choice to the next part of the program sequence.
+ 2
Sure. You can include the option that if they choose anything invalid, they are told to choose from the options.
Switch would be something like:
Switch
Case 1: Fib
Case 2: Fact
Default: choose 1 or 2
If:
If 1 -> Fib
Else if 2 -> Fact
Else -> choose 1 or 2
0
Lothar
ohh i dont know where to start in this program so I'm asking how.
and maybe if i could find that booster i could do my homework by myself. im not asking for anyone to solve my entire homework. i also want to do it myself. because i also want to learn
hope you understand
0
Ausgrindtube
hmm do u know any way to make the user pick one of the two?
0
Manav Roy no. they are separated
first the program will ask the user what operation, if Fibonacci or Factorial. and if he pick Fibonacci, an input is required and then will solve what is its Fibonacci.
if Factorial an input is required and then will solve again for its factorial.
should i create another method for Factorial and another for Fibonacci?
should i use switch case?
and example if the user chose Factorial how will i call the method Factorial?