Two functions in a program (factorial and fibonacci) help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

24th Feb 2022, 3:21 PM
Japheth
6 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!
24th Feb 2022, 3:31 PM
Lothar
Lothar - avatar
+ 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.
25th Feb 2022, 2:54 AM
Ausgrindtube
Ausgrindtube - avatar
+ 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
25th Feb 2022, 3:33 AM
Ausgrindtube
Ausgrindtube - avatar
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
24th Feb 2022, 3:35 PM
Japheth
0
Ausgrindtube hmm do u know any way to make the user pick one of the two?
25th Feb 2022, 3:22 AM
Japheth
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?
26th Feb 2022, 5:57 AM
Japheth