### Fibonacci Numbers? Help on while loop

Having trouble with the while loop in this code. I'm trying to get the 9th term of the Fibonacci numbers. For instance if I input 1 for number1 and number2, then input the number of which term from the sequence I want from the Fibonacci number, in my case I did 9. All I get then is just a blank cursor on the next line.

Anyone know whats wrong with my loop??

 ``123456789101112131415161718192021222324252627282930313233343536373839`` `````` int _tmain(int argc, _TCHAR* argv[]) { //declare two variabes int number1; int number2; int nextnumber; int counter=2; //Declare the variable for which numbered sequence the user wants int whatsequenceuserwants; //Ask user for two numbers cout<<"\n\tNumber 1: "; cin>>number1; cout<<"\n\tNumber 2: "; cin >> number2; //Ask the user for what term of number they want cout<<"\n\n\tWhat term from the sequence do you want? "; cin>>whatsequenceuserwants; //formula for finding the next number if (whatsequenceuserwants==1) {cout<<"First Number: " <=3 && counter==whatsequenceuserwants) {nextnumber= number1+number2; if(whatsequenceuserwants==counter) cout<<"Number is" <
From what I can see in order to satisfy your while loop requirements whatsequenceuserwants needs to be greater than or equal to 3 and counter needs to be equal to whatsequenceuserwants. This can't happen because you set counter = 2 and whatsequenceuserwants needs to be 3 or greater, so 2 != 3.
I understand what your saying :) I have changed my code a little; however, when I want to find the position of the 9th Fibonacci number, all I get is

"Number is2"

 ``12345678910111213141516171819202122232425262728293031323334353637383940`` ``````int _tmain(int argc, _TCHAR* argv[]) { //declare two variabes int number1; int number2; int nextnumber; int counter=3; //Declare the variable for which numbered sequence the user wants int whatsequenceuserwants; //Ask user for two numbers cout<<"\n\tNumber 1: "; cin>>number1; cout<<"\n\tNumber 2: "; cin >> number2; //Ask the user for what term of number they want cout<<"\n\n\tWhat sequence of number do you want? "; cin>>whatsequenceuserwants; //formula for finding the next number if (whatsequenceuserwants==1) {cout<<"First Number: " <
Topic archived. No new replies allowed.