The question is: For different r of 0.2-2.0 by 0.2 show 11 iterations (0-10) of x[n+1]=x[n]*r+1.0. Start with x[0]=0.0. This is what I have so far and I feel like i'm very far off:

#include <cstdlib>

#include <iostream>

#include <cmath>using namespace std;

int main( )

{

int counter = 0;

while (counter < 11)

{

cout << counter << "\n";

}

cout << counter <<endl;double result = counter*[counter+1];

int r = 0.2;

while ( r<11 )

{

cout << r << "\n";

r+=0.2;

}

cout << result=counter*[counter]*r+1.0 << endl;

}

system ("PAUSE");

return EXIT_SUCCESS;

}

I need help!

i could just write it, but then you don't really learn much that way do you?

so i'll just give some helps, (and this is purely my own approach, there's almost always more than one way to do things with programming):

first of course set x[0]=0.0,

then i would use a for loop:

for (( r=.2,r<2.2,r+=.2 ))

then use r to get n by multiplying: n=r*5

then set x[n]=x[n-1]*r+1

(since the calc'd n starts at one, you have to refer to

nminusone instead of n plus one.)

not tested, not sure i'm on the right track, but that is where

i would start from.

r doesn't go to 11, x does. r goes to 2. you could also use

a counter to get n, but i think it's "cleaner" to just calc it.

note that x ends at 10, not 11 (but it has 11 values: [0]-[10]).

Usually, especially with C, for me, it is much easier to code it in either pseudocode or BASIC (since it's such an easy language, it's almost pseudocode anyway). That way, you master the concepts first, before tackling the gritty syntax of C.

Hth

Ask Your Question

Weekly Poll

Do you think Europe's new data protection laws will affect you?

Discuss in The Lounge

Poll History