Author Topic: Problem regenarating numbers the second time around..  (Read 381 times)

Offline sider the spider

  • Single posting newcomer
  • *
  • Posts: 2
Problem regenarating numbers the second time around..
« on: February 23, 2017, 06:42:02 am »
Hi
i created a program regenerating Fibonacci sequence..

The code works well except one detail

When the program tries to regenerate a sequence the second time around it does not show the numbers at all..

I do not think I have an issue with my code I suspect it is a code blocks false configuration.. 

here is my main:

#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include "Fibonacci_Library.h"

using namespace std;

int main()
{
    // Variables
    unsigned int upToNumber;
    unsigned int firstNumber = 0, nextNumber = 0;
    unsigned int secondNumber = 1;
    char choice = 'y';

    while((choice == 'y') || (choice == 'Y'))
    {
        //             ******************  TITLE  *******************

        cout << "\n"
               << "\t\t\t\t\t   The Fibonacci Sequence     "
               << "\n"
               << "\t\t\t\t\t **************************   "
               << "\n";

        cout << "\n"
               << "\t\t\t This program creates the Fibonacci Sequence up to a number"
               << "\n"
               << "\t\t\t\t     that is specified by you (The user)."
               << "\n";


        cout << "\n\n"
               << "Up to what number you want to create the Fibonacci Sequence? ";

        upToNumber = getNumber();

        //            ***********  Fibonacci Algorithm  ************

        while (nextNumber <= upToNumber)
        {
            cout << nextNumber << endl;
            nextNumber = firstNumber + secondNumber;
            secondNumber = firstNumber ;
            firstNumber = nextNumber;
        }

        cout << "Do you want to create the Fibonacci Sequence up to a different number "
               << "This time? ";

        choice = getLetter();
        while ( (choice != 'y') && (choice != 'Y') && (choice != 'n') && (choice != 'N') )
        {
            cout << "\n"
                   << "Please type \"Yes\" or \"No\" ";
            choice = getLetter();
        }
        system("cls");
     }

cout << "\n"
       << "Press any key to terminate program...  ";

getch();
return 0;
}
 

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1506
Re: Problem regenarating numbers the second time around..
« Reply #1 on: February 23, 2017, 07:22:21 am »
This type of issue cannot be caused by C::B; the issue is within your code.  I recommend you step through it with the debugger.  The debugger is your friend.

If you are unable to find the cause, try asking on a programming forum (this is not the place for generic programming questions).

Offline sider the spider

  • Single posting newcomer
  • *
  • Posts: 2
Re: Problem regenarating numbers the second time around..
« Reply #2 on: February 24, 2017, 04:06:27 am »
I thank you very much sir, "Alpha".

My code had the problem after all. I managed and fixed it. I realized after you said it was my code problem.
I am sorry for putting such a question at the wrong place, I am relatively new to c++ and I code out of hobby and just some math curiosities that I have with numbers.