### Fibonacci Series Help (Period Problem)

Hey everyone,

I was asked to write a code that has the user input a number and then the computer calculates it for the Fibonacci series. The output should be separated by commas and a period should follow the last number. Ex. 1,2,3,4,5. <---period

I can't seem to get the period at the end. I have the commas and everything else. Thanks for the help! =) Here is my code:
 ``` #include "stdafx.h" #include using namespace std; int main() { double num; cout << "How many Fibonacci numbers do you want to display?"; cin >> num; if (num >= 0 && num <= 100) { double a = 0; double b = 1; double sum; for (double i = 0; i < num; i++) { cout << a << ", "; sum = a + b; a = b; b =sum; } } else cout << "Error! Please enter a number in the range of 0-100."; system("pause"); return 0; } ```

check this out

 ``12345678910111213141516171819202122232425262728293031323334353637`` ``````#include using namespace std; int main() { double num; cout << "How many Fibonacci numbers do you want to display?"; cin >> num; if (num >= 0 && num <= 100) { double a = 0; double b = 1; double sum; for (double i = 0; i < num; i++) { cout << a << ", "; sum = a + b; a = b; b =sum; } cout << a; // <<<<<<< here } else cout << "Error! Please enter a number in the range of 0-100."; return 0; }``````
Last edited on
Oh, I see now! Thanks so much!
#include <iostream>
using namespace std;

int main()
{
double num;
double i;

cout << "How many Fibonacci numbers do you want to display?";
cin >> num;

if (num >= 0 && num <= 100)
{
double a = 0;
double b = 1;
double sum;

for (i = 1; i <= num; i++)
{
cout << a ;
sum = a + b;
a = b;
b =sum;
if (i<num){
cout << ", ";
}
}

if (i=num)
{
cout << ".";
}
}

else

cout << "Error! Please enter a number in the range of 0-100.";

cin.get();

return 0;

}
Topic archived. No new replies allowed.