S
Stephan Aspridis
Hi folks,
a happy new year. I have a little problem with a program I am writing at
the moment. A loop doesn't behave the way I'd like to (namely, the
"break" is ignored). This is the code in question:
----------------------------------
star.planet[0].orbit_distance =
pow(SOLDENSITY/EARTHDENSITY,1.0/3.0)*sqrt(star.mass)*get_random(50.0,150.0)/100.0;
for (p=0;p<orbcount-1;p++){
x = p+1;
star.planet[x].orbit_distance =
star.planet[p].orbit_distance*get_random(1250.0,2500.0)/1000.0;
if (star.planet[p].orbit_distance>star.orbit_limit)
break;
}//end for
star.number_of_orbits = p;
----------------------------------
"orbcount" is a variable of type int which normally has a value between
1 and 20. "star.orbit_limit" is an upper limit (type double).
The general idea was that upon reaching the limit, the loop ends and
"star.number_of_orbits" gets the last value of "p".
I asked the same question in de.comp.lang.c and the folks there came up
with this solution:
----------------------------------
ptr = star.planet;
e = ptr+orbcount;
d =
pow(SOLDENSITY/EARTHDENSITY,1.0/3.0)*sqrt(star.mass)*get_random(50.0,150.0)/100.0;
while (d<=star.orbit_limit&&ptr<e){
ptr->orbit_distance = d;
d *= get_random(1250.0,2500.0)/1000.0;
++ptr;
}//end while
star.number_of_orbits = ptr-star.planet;
----------------------------------
Problem is: It doesn't work either. I get the same error. To illustrate
what I mean here is an example of a system generated with this program:
-------------------------------
stellar characteristics of 1
type : K3 V
mass : 0.689 solar mass
luminosity : 0.225 solar lum
temperature : 4518 K
peak wavelength : 596 nm
diameter : 1081470 km
gravity : 31.519 G
lifespan : 30.581 billion years
rotational period : 193.5 hours
axial inclination : 18.0 deg.
number of orbits : 13
orbital limit : 4.286 AU <------ this is the limit...
eco zone
-inner boundary : 0.463 AU
-outer boundary : 0.743 AU
%
planets of 1 present at:
0.549 AU
1.208 AU
2.257 AU
5.395 AU <----- ...that is ignored
11.480 AU
14.862 AU
35.608 AU
51.075 AU
113.629 AU
224.052 AU
445.400 AU
765.494 AU
1840.211 AU
-------------------------------
Any idea anyone? I use lcc-win32 and gcc, so it probably isn't the compiler.
hoping for answers,
regards,
Stephan
a happy new year. I have a little problem with a program I am writing at
the moment. A loop doesn't behave the way I'd like to (namely, the
"break" is ignored). This is the code in question:
----------------------------------
star
pow(SOLDENSITY/EARTHDENSITY,1.0/3.0)*sqrt(star
for (p=0;p<orbcount-1;p++){
x = p+1;
star
star
if (star
break;
}//end for
star
----------------------------------
"orbcount" is a variable of type int which normally has a value between
1 and 20. "star
The general idea was that upon reaching the limit, the loop ends and
"star
I asked the same question in de.comp.lang.c and the folks there came up
with this solution:
----------------------------------
ptr = star
e = ptr+orbcount;
d =
pow(SOLDENSITY/EARTHDENSITY,1.0/3.0)*sqrt(star
while (d<=star
ptr->orbit_distance = d;
d *= get_random(1250.0,2500.0)/1000.0;
++ptr;
}//end while
star
----------------------------------
Problem is: It doesn't work either. I get the same error. To illustrate
what I mean here is an example of a system generated with this program:
-------------------------------
stellar characteristics of 1
type : K3 V
mass : 0.689 solar mass
luminosity : 0.225 solar lum
temperature : 4518 K
peak wavelength : 596 nm
diameter : 1081470 km
gravity : 31.519 G
lifespan : 30.581 billion years
rotational period : 193.5 hours
axial inclination : 18.0 deg.
number of orbits : 13
orbital limit : 4.286 AU <------ this is the limit...
eco zone
-inner boundary : 0.463 AU
-outer boundary : 0.743 AU
%
planets of 1 present at:
0.549 AU
1.208 AU
2.257 AU
5.395 AU <----- ...that is ignored
11.480 AU
14.862 AU
35.608 AU
51.075 AU
113.629 AU
224.052 AU
445.400 AU
765.494 AU
1840.211 AU
-------------------------------
Any idea anyone? I use lcc-win32 and gcc, so it probably isn't the compiler.
hoping for answers,
regards,
Stephan