sequence loop

How do I restrict the print out of this sequence to just N or so terms? I am wanting to print no more than 30 or so and at the moment im getting the program running continuously

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
  int N;




  do {
  cout << "Enter the number of terms you wish to print (N):" << endl;
  cin >> N;
  } while ( (N == 0)) ;

   for (float i=1; i<=10; i=1+(1/i))

  printf ("%12.10g" , i );


  return 0;

}

  
Line 17: What value of x will make this true: 10 < 1+(1/x)?


Do not use the float term in the loop condition.
So x > 1/9 would make that true?
i tends to 1.6180... as the sequence progresses so my i<=10 is never reached.
what would the condition be? so do I need to make a new variable x for the condition?
thanks for your help
1
2
3
4
5
6
7
8
float i = 1;
int n = 0;
while ( n < N )
{
  // print i
  i = ... // update i for next round
  ++n;
}
great got it now thanks for the help
Topic archived. No new replies allowed.