Write me a function in C++ to find the distance between two points
- User
Write me a function in C++ to find the distance between two points
- Assistant
Of course:
#include <math.h>
double dist(double a, double b){ return sqrt(pow(a, 2) + pow(b, 2)); }
The function uses the Pythagorean theorem to calculate and return the euclidian distance between two points, in the function named 'a', and 'b'.
- User
I think you got confused? I want to find the distance between any two points, but it seems your function only returns the distance between points (0,0) and (a,b)?
- Assistant
You are correct, here is a corrected function:
#include <math.h>
double dist(double x_1, double y_1, double x_2, double y_2){ return sqrt(pow(x_2 - x_1, 2) + pow(y_2 - y_1, 2)); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)