Fibonacci Sequence

I am writing a program that asks a user for a number between 5 and 11, and then displays that many fibonacci numbers. I am very close to solving it, and it works with some of my tests ( for example when i enter 5, it gives me a total of 7) but it does not show me the numbers it adds up ( so it should show me 0, 1, 1, 2, 3. If anyone had a suggestion for something to try to display the numbers it would be appreciated!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
int fibonacci (int num) {
int total;
total = ((num-1) + (num-2));
return total;
}
int main () {
int num;
int total;
cin>> num;
cout<< "please enter a num between 5 and 11:";
cout<< num;
cout<< endl;
if (( num<5) || (num11)) {
cout<< "please follow directions";
cout<< endl;
}
else {
total = fibonacci(num);
cout<< endl;
cout<< "total is";
cout<< total;
cout<< endl;
}
return 0;
}
I am still trying to work through this problem, and am having trouble display the numbers that add up to the total. I am not sure if I need to implement a while or if statement in my fibonacci function, so far what I have tried has not worked. If anyone has a direction to go in that be great!
Topic archived. No new replies allowed.