I feel I must be missing something, because I do not understand what problem you're having. Here's how I think it would be done:
Code:
struct primary_plot pri_plot;
struct secondary_plot sec_plot;
struct aircraft_information ac_info;
struct aircraft_information {
ac_info.bearing = pri_plot.bearing; /*degrees */
ac_info.range = pri_plot.range; /*metres */
ac_info.range /= 1000.0; /*kilometres */
ac_info.altitude = sec_plot.altitude; /*metres */
ac_info.flight_number = sec_plot.flight_number;
Of course, I'm assuming that the corresponding bearing and range values are the same in both the primary and secondary plots. Otherwise, you'll have to make a determination as to which one you want to use.
Was your question about how to handle the conversion of the range from int to double? In C, some simple data type conversions are automatic, like int to long int, float to double, and int to double. In many cases, you would need to use type casting to explicitly tell the compiler to perform a conversion; eg:
Code:
ac_info.range = (double)pri_plot.range / 1000.0; /*kilometres */
That explicitly converts the integer value to a double before it gets divided by the double constant 1000.0.
Sometimes, these automatic conversions within mixed-type arithmetic expressions can cause unexpected results. For example, this test program:
Code:
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
double dRange;
int iRange = 4500;
dRange = iRange / 1000.0;
printf("%d -> %g\n",iRange,dRange);
dRange = iRange / 1000;
printf("%d -> %g\n",iRange,dRange);
return 0;
}
produced this output:
In the first case, the 1000.0 indicated a floating-point divide, so iRange was converted to double before the divide. To be honest, I had expected the int variable to cause the constant to be converted to int, because normally the left-hand term in an operation determines the data type of the result.
In the second case, an integer divide was performed, which discards any remainder, and then the quotient was converted to double for the assignment. One would have assumed the result to be 4.5, but automatic conversion gave an unexpected result.
In general, if your math expressions give unexpected results and they appear correct, then it may be due automatic type conversion.
I hope that I addressed your question and that this helps.