See the description of the definition of the Fibonacci number sequence on the fo
ID: 3642343 • Letter: S
Question
See the description of the definition of the Fibonacci number sequence on the following link: http://en.wikipedia.org/wiki/Fibonacci_numberYou only need to read the first three paragraphs.
You are to write a program that asks the use to enter an integer n and then print out the Fibonacci sequence that ends with the number Fn. The integer n must be greater than or equal to zero.Your program must have a function that calculates and prints the Fibonacci sequence.
The output should look exactly like what is after the colon. Rows, commas, (...) should all be in the code, except the words input/output.
Input: 0
Output: Which Fibonacci number do you want to find?
0...
Input: 1
Output: Which Fibonacci number do you want to find?
0, 1...
Input: 2
Output: Which Fibonacci number do you want to find?
0, 1, 1...
Input: -1, -100, 3
Output: Which Fibonacci number do you want to find?
The number entered must be greater than or equal to zero
Which Fibonacci number do you want to find?
The number entered must be greater than or equal to zero
Which Fibonacci number do you want to find?
0, 1, 1, 2...
Input: 10
Output: Which Fibonacci number do you want to find?
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55...
Input: 11
Output: Which Fibonacci number do you want to find?
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89...
Input: 12
Output: Which Fibonacci number do you want to find?
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89...
Input: 13
Output: Which Fibonacci number do you want to find?
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233...
This is what I have so far:
#include <iostream>
using namespace std;
void printFibonacci(int n)
{
int first = -1;
int second = 1;
int third = 0;
int i=0;
while(i<=n)
{
third = first + second;
first = second;
second = third;
cout<< ", "<<third;
i++;
}
}
int main()
{
int n;
cout<<"Which Fibonacci number do you want to find? ";
cin>>n;
if(n<0)
{
cout<<"The number entered must be greater than or equal to zero ";
cout<<"Which Fibonacci number do you want to find? ";
cout<<"The number entered must be greater than or equal to zero ";
cout<<"Which Fibonacci number do you want to find? ";
return 0;
}
printFibonacci(n);
cout<<"... ";
return 0;
}
MY QUESTION IS: HOW DO ADD THE COMMAS AND (...) IN THE RIGHT PLACE?