Whenever i enter some input and press enter i first get my random number from 0-2 (bold in the code).
The program then goes on to only output 1 (in italics) although my if condition would result in an output of (0-2) (the same i get in the first output).
This is not the case though. If I comment out the first "else if" and leave the second "else if" the program only chooses to show the 2 (underlined) neglecting my random number.
Is there any way to make the program work as intended?
greetings
8. Create a program which generates Fibonacci series till a number 'n' where 'n' is entered by the user. For eg. if the user enters 10 then the output would be: 1 1 2 3 5 8 (Beginner)
Your if statements are doing something completely different from what you think.
The first thing to note is that you're not testing for equality, instead, you're assigning a new value to number. After the assignment, number is evaluated to a Boolean. This mistake is common amongst beginners. Alls' you have to do is change number = 0 to number == 0. For instance: