Herons formula
The task is as follows: Enter the lengths of the triangles a, b, and c. If three sides do not form a triangle, repeat the procedure (page entry, etc.), otherwise calculate using Heron formula the area of ââa triangle and print it to one decimal place. My code seems so work fine, except the part where it should repeat the procedure if inputs do not form a triangle, instead it outputs 0 or nan. Not sure if its the problem in do-while loop or something else. #include <iostream> #include <math.h> #include <string.h> using namespace std; float heron (float, float, float); void triangle(){ float a, b, c; do { cin >> a; cin >> b; cin >> c; } while ((a+b<c) && (a+c<b) && (b+c<a)); ; cout << ceil((heron(a, b, c)*10))/10 << endl; } int main(){ triangle(); } float heron (float a, float b, float c){ float s=(a+b+c)/2; return sqrt(s*(s-a)*(s-b)*(s-c)); }