Area / Perimeter of triangle

I don't get why area is not working?

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
#include <iostream> 
#include <cmath> 
#include <iomanip> 
using namespace std;

int main()
{
   //initialize identifiers 
    float AreaTri= 0.00;
    float p= 0.00; 
    float a= 0.000, b= 0.00, c= 0.00;
     
    //Enter values
	cout << "Enter the measure of all three sides of a triangle: "; 
	cin >> a; cin >> b; cin >> c;

	cout << "         /\\     " << endl;
	cout << "        /  \\     " << endl;
        cout << "    a  /    \\ b    " << endl;
        cout << "      /      \\     " << endl;
	cout << "      --------      " << endl;
	cout << "         c     " << endl;

	AreaTri= sqrt(p*(p-a)*(p-b)*(p-c));
	p= (a+b+c)/2.; 

	cout << "Area = " << AreaTri << endl; 
	cout << "Perimeter = " << p << endl; 

	//terminate program
	system("pause");
	return 0;
}
hello
1.
not working
is useless information. can you bit more desriptive?
2. p is zero, you don't set this to anything other than zero, and when you multiply something by zero, you get zero. I'm talking about line number 24.
3. line 24: why are you dividing your perimeter by 2?
Last edited on
so do I have to change it?
I thought it would change automatically after I made p= (a+b+c)/2
I think I got it, I just put it before.
3. line 24: why are you dividing your perimeter by 2?
I thought it would change automatically after I made p= (a+b+c)/2

No. When you assign a value to a variable, it assigns the value as it's computed at that point in the code. It does not assign the formula that you give it.

A couple of other things:
Line 15 could be simplified as cin >> a >> b >> c; Pretty cool, huh!

It seems to me that it would be more useful to put lines 17-22 before line 14. That way the user would know what the values mean.
Topic archived. No new replies allowed.