Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <cmath>
- using namespace std;
- double square_triangle(double, double, double);
- int main()
- {
- double a, b, c;
- a = 3; b = 4; c = 5;
- try{
- double s = square_triangle(a, b, c);
- cout << s << endl;
- }
- catch (int code)
- {
- if (code==1)
- cerr << "Those are non-triangle sides";
- else
- cerr << "Unknown error";
- }
- return 0;
- }
- double square_triangle(double x, double y, double z)
- {
- if (((x + y) > z) && ((x + z) > y) && ((y + z) > x))
- {
- double p = (x + y + z) / 2.0;
- return sqrt(p*(p - x)*(p - y)*(p - z));
- }
- else
- {
- throw 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement