Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // fibonacci - just to see if i know what the hell I'm doing
- #include <iostream>
- using namespace std;
- int main()
- {
- int current, previous1, previous2, nthFibonacci;
- bool done = false;
- cout << "Enter the first two numbers of the fibonacci: ";
- cin >> previous1 >> previous2;
- cout << "Enter the nth Fibonacci you want: ";
- cin >> nthFibonacci;
- cout << endl;
- if (!cin.good())
- {
- cin.clear();
- cin.ignore(100, '\n');
- cout << "Numbers only you letter-aholic!" << endl;
- }
- else if(previous1 <= 0 || previous2 <= 0 || nthFibonacci <= 0)
- {
- cout << "Enter numbers over 0 for all prompts." << endl;
- }
- else
- {
- cout << previous1 << " " << previous2 << " ";
- while (!done)
- {
- if (nthFibonacci == 1)
- {
- current = previous1;
- }
- else if (nthFibonacci == 2)
- {
- current = previous2;
- }
- else
- {
- int counter = 3;
- while (counter <= nthFibonacci)
- {
- current = previous1 + previous2;
- previous1 = previous2;
- previous2 = current;
- cout << current << " ";
- counter++;
- }
- }
- cout << "\nThe " << nthFibonacci << "th fibonacci is : " << current << endl;
- done = true;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment