Hey guys, I'm fairly new to coding, in fact, this is the second program I've ever tried haha. I can't quite work out why my loop is terminating early in this program:
Code:
#include <stdio.h>
int main () {
int fibonacci, fib3, fib2, fib1;
printf("What number would you like the series to go to?");
scanf("%d", &fibonacci);
printf("%d\n", fibonacci);
fib2=1;
fib1=0;
if (fibonacci = 0) {
printf("The series is 0");
return 0;
}
do {
fib3 = fib2 + fib1;
printf("%d+\n",fib3);
fib1=fib2;
fib2=fib3;
}
while (fib3 <= fibonacci);
return 0;
}
All I get as an output, when say putting in 9 as the input, is this:
What number would you like the series to go to?9
9
1+
Obviously it's going through the loop once, before deciding it's ready to terminate without going through again. I can't work out why it wants to terminate without looping through twice. Any help you could offer would be great, thanks!