Hello,
As you can see the title, i need help with the loop. Here is the code:

double t;
	for(t=0.5;t>2.5;t=t+0.1){
	System.out.println(form.format(t));
        }

As you can see, the loop keeps going from 0.5 to 2.5. The main problem, that i cant understand how to make it count from 0.5 to 2.5, with this algorythm:
0.5 + 0.1 = 0.6
0.6 + 0.1 = 0.7
0.7 + 0.3 = 1
1 + 0.1 = 1.1
1.1 + 0.1 = 1.2
1.2 + 0.3 = 1.5
1.5 + 0.1 = 1.6
1.6 + 0.1 = 1.7
1.7 + 0.3 = 2
2 + 0.1 = 2.1
2.1 + 0.1 = 2.2
2.2 + 0.3 = 2.5

Iam stuck with this 2 days, and tomorrow i have to show this =(

The correct code would be :

double t=0.5;

for(i=0;i<n;i++)
{
if((t+0.3)%0.5==0)
{t=t+0.3;
}

else t=t+0.1;

}

Works now?

Real thx for the algorithm, but I cant make it work in the correct way =(
Problem is, that i still cant understand how to make the loop, and print it like:
0.5 , 0.6 , 0.7 , 1 , 1.1 , 1.2 , 1.5 , 1.6 , 1.7 , 2 , 2.1 , 2.2 , 2.5

for(t=0.5;t<2.5;)
    {
                     if((t+0.3)%5==0)
                     {
                              cout<<t+0.3;
                              }
                              
                              else cout<<t+0.1;
                              }
                              }

This? My compiler didn't let me compile, but it's known to have problems AND I tried it out in C++...

Thx again, but i cant make it work ;)
Working under Eclipse(JDK), trying to make that "damn" loop. 2 days(8+ hours in Eclipse, and still cant make it). Iam a dummy =(

Hehe, you ain't alone there lol, I can't get it to work here either...
It's 1:35 here, gotta get some sleep...

TC

This increment will work

t += (count%3==0 ? 0.3 : 0.1);

but you'll have to figure out the loop to go around it. It's not a complex one.

This increment will work

t += (count%3==0 ? 0.3 : 0.1);

but you'll have to figure out the loop to go around it. It's not a complex one.

thx, i will give it a try.. My brain going to boom soon ^_^

It works just fine in the loop I ran here. Since you didn't trouble to post your code, no one can tell you exactly why yours is not working.

This article has been dead for over six months. Start a new discussion instead.