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 55 56 57
|
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
double point_length(double init_x, double init_y, double land_x, double land_y){
double length = sqrt(((init_x-land_x)*(init_x-land_x))+((init_y-land_y)*(init_y-land_y)));
return length;
}
int main()
{
double midman(0);
double x1(0);
double y1(0);
double x2(0);
double y2(0);
double x3(0);
double y3(0);
// here is the for loop I added
for (int i(1); i <= 3; i++) {
printf("Enter x value with Cardinality: %i \n", i);
cin >> midman;
switch(i) {
case 1: x1 = midman;
break;
case 2: x2 = midman;
break;
case 3: x3 = midman;
break;
}
printf("Enter y value with Cardinality: %i \n", i);
cin >> midman;
switch(i) {
case 1: y1 = midman;
break;
case 2: y2 = midman;
break;
case 3: y3 = midman;
break;
}
}
// loop ends
double first_d = point_length(x1,y1,x2,y2);
double second_d = point_length(x2,y2,x3,y3);
double third_d = point_length(x3,y3,x1,y1);
double semiperimeter = (first_d+second_d+third_d)/2;
double area = sqrt(semiperimeter*(semiperimeter-first_d)*(semiperimeter-second_d)*(semiperimeter-third_d));
cout << endl << "The area of your triangle is: " << area;
return 0;
}
|