Tidy things up... TinyGPS check coordinates


At the moment I'm working on a project with GPS involved. (TinyGPS++ library) My programming skills are not that good... (I just copy-paste and try things) It needs to check if a pre defined coordinate (waypoint) is reached. For now I just check each with this block of code and I copied this block for WP2 and WP3:

//WayPoint Coordinates
static const double WP1_LAT = 51.933397, WP1_LON = 5.147241; // Waypoint 1
static const double WP2_LAT = 51.933159, WP2_LON = 5.147750; // Waypoint 2
static const double WP3_LAT = 51.933543, WP3_LON = 5.147471; // Waypoint 3


  unsigned long distanceToWP1 =
    (unsigned long)TinyGPSPlus::distanceBetween(
  printInt(distanceToWP1, gps.location.isValid(), 9);

  double courseToWP1 =

  printFloat(courseToWP1, gps.location.isValid(), 7, 2);

  const char *cardinalToWP1 = TinyGPSPlus::cardinal(courseToWP1);

  printStr(gps.location.isValid() ? cardinalToWP1 : "*** ", 6);

But I want to tidy this block and use it as a function, with statements within the brackets. How could I do this? What this block uses as input are the coordinates on top of the code

Things that will change in this block are: •distanceToWP (1, 2 or 3) •courseToWP (1, 2 or 3), and •cardinalToWP (1, 2 or 3).

I think I need to place the coordinates in an array?

I hope someone could help me out. Thanks in advance! Dave

But I want to tidy this block and use it as a void with statements within the brackets

A "void" is nothing, a hole, an emptiness.

Did you mean a function? And yes, you probably want to put those values into an array.

That's what I mean, a function ;)

But I can't figure out how I could do this. Can You give me some advice? Thanks!

Could someone give me some advice how to do this?