# Result of For Loop

Page 1 of 1

## 6 Replies - 875 Views - Last Post: 07 November 2009 - 11:29 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=136895&amp;s=c2fa4725bac9d6437165860961b2afd0&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 kenryuakuma

• D.I.C Regular

Reputation: 4
• Posts: 408
• Joined: 14-December 08

# Result of For Loop

Posted 05 November 2009 - 04:31 PM

Chao theory.

Take a double or float value X between 0 and 1 as a starting value. Generate a new value for X by the equation: X = 2 * X * (1 - X); Display X. Write a program that asks the user for a starting value X, then perform the above process in loop that runs through 50 cycles, while display the value of X.

Read my question. I HAVE DONE THIS ALREADY. This seems pretty easy to do. But after I did everything correctly, I got the very strange result.

The result I got is:
X = 1.xxxxxxxxxxxxxxxx + Exxx;
X = -infinity.

I got all the minus(- infinity) infinity result. I hope you guys could do this thing and run this code and tell me what the result you guys got.

```Console.Write("enter a number: ");

for(int i = 1; i <= 50; i++)
{
X = 2 * X * (1 - X);
Console.Write(X);
}

```

This post has been edited by kenryuakuma: 05 November 2009 - 04:48 PM

Is This A Good Question/Topic? 0

## Replies To: Result of For Loop

### #2 Momerath

• D.I.C Lover

Reputation: 1020
• Posts: 2,463
• Joined: 04-October 09

## Re: Result of For Loop

Posted 05 November 2009 - 06:13 PM

What's the very first line of your problem? What did you declare X as?

### #3 KeyboardKowboy

Reputation: 20
• Posts: 142
• Joined: 15-December 08

## Re: Result of For Loop

Posted 05 November 2009 - 09:02 PM

Quote

Take a double or float value X between 0 and 1 as a starting value.

Why are you parsing X as an int if you specify that it should be a double or a float?

### #4 kenryuakuma

• D.I.C Regular

Reputation: 4
• Posts: 408
• Joined: 14-December 08

## Re: Result of For Loop

Posted 05 November 2009 - 11:02 PM

oh mistake, yes it should be float and double. SORRY! Yes, the program code was double when I did it but I forgot to use double to post my problem because I get used to int already.

### #5 KeyboardKowboy

Reputation: 20
• Posts: 142
• Joined: 15-December 08

## Re: Result of For Loop

Posted 05 November 2009 - 11:21 PM

Ok... Well I'm still not sure what you are trying to do, but I took your code and modified it so that it actually read in a double value.
I also chose to output a WriteLine, instead of Write, for readability.

```class Program
{
static void Main(string[] args)
{
Console.Write("enter a number: ");

for (int i = 1; i <= 50; i++)
{
X = 2 * X * (1 - X);
Console.WriteLine(X);
}
}
}

```

The results are below: (click to expand image)

### #6 kenryuakuma

• D.I.C Regular

Reputation: 4
• Posts: 408
• Joined: 14-December 08

## Re: Result of For Loop

Posted 07 November 2009 - 11:22 PM

Thanks the problem has been resolved in class. However, if you enter a great or big number, the result is gonna infinity and is kind of weird.

### #7 Momerath

• D.I.C Lover

Reputation: 1020
• Posts: 2,463
• Joined: 04-October 09

## Re: Result of For Loop

Posted 07 November 2009 - 11:29 PM

That's why the problem says a number between 0 and 1

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }