chatGPT writes and executes Harbour code !!!
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
https://chat.openai.com/chat
And not only writes it and fixes it, if required, but also is able to execute the code and let you know the results...
> write the result for the above call to Planets( 12, 6 )
And not only writes it and fixes it, if required, but also is able to execute the code and let you know the results...
- Code: Select all Expand view
- #include "hbapi.h"
#include "hbmath.h"
// Constant for the number of days in a year
#define DAYS_PER_YEAR 365.24
// Structure to represent a planet
typedef struct {
char *name;
double distance_from_sun; // in millions of kilometers
double year_length; // in Earth days
} planet_t;
// Array of planets in the solar system
planet_t planets[] = {
{ "Mercury", 57.9, 87.97 },
{ "Venus", 108.2, 224.68 },
{ "Earth", 149.6, 365.24 },
{ "Mars", 227.9, 686.98 },
{ "Jupiter", 778.6, 4332.82 },
{ "Saturn", 1427.0, 10759.22 },
{ "Uranus", 2871.0, 30688.5 },
{ "Neptune", 4497.1, 60182.0 }
};
// Function to calculate the position of a planet
// given the number of days since the start of the year
double calculate_position(planet_t planet, double days_since_start_of_year) {
double orbit_fraction = days_since_start_of_year / planet.year_length;
return fmod(orbit_fraction, 1.0) * 360.0;
}
HB_FUNC( PLANETS ) {
// Check for the correct number of arguments
if ( hb_pcount() != 2 ) {
hb_retc( "Usage: PLANETS( <month>, <day> )" );
return;
}
// Parse the month and day from the command line arguments
int month = hb_parni( 1 );
int day = hb_parni( 2 );
// Calculate the number of days since the start of the year
double days_since_start_of_year = (month - 1) * 30.4 + day;
// Create a string to hold the output
char *output = (char*) hb_xgrab( 1024 );
sprintf( output, "Planet\t\tPosition\n" );
// Calculate the positions of the planets
for (int i = 0; i < sizeof(planets) / sizeof(planet_t); i++) {
double position = calculate_position(planets[i], days_since_start_of_year);
sprintf( output + strlen( output ), "%s\t\t%.2f degrees\n", planets[i].name, position );
}
// Return the output string
hb_retc( output );
hb_xfree( output );
}
> write the result for the above call to Planets( 12, 6 )
Planet Position
Mercury 35.99 degrees
Venus 211.38 degrees
Earth 347.00 degrees
Mars 56.32 degrees
Jupiter 175.49 degrees
Saturn 132.94 degrees
Uranus 286.76 degrees
Neptune 212.01 degrees