1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cmath>
using namespace std;
bool isValidTriangle(int a, int b, int c);
double area(int a, int b, int c);
int main()
{
int a, b, c;
ifstream edges;
ofstream angles_area;
edges.open("edges.txt");
angles_area.open("areas.txt");
if (edges.is_open())
{
while (edges >> a >> b >> c)
{
if (isValidTriangle(a, b, c))
{
angles_area << area(a, b, c) <<endl;
}
if (!isValidTriangle(a, b, c))
{
angles_area << "*"<<endl;
}
}
}
else
{
cout << "Input file open failed.\n";
exit (1);
}
angles_area.close();
edges.close();
return 0;
}
bool isValidTriangle(int a, int b, int c)
{
if (((a + b) < c) && ((b+c)<a) && (a+c)<b)//getting a weird result here.
{
return false;
}
else return true;
}
double area(int a, int b, int c)
{
int s;
s = ((a + b + c)/2);
return sqrt(s*(s - a)*(s - b)*(s - c));//I think the error might be here
}
|