#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int l,b,h;
int s;
s=(l+b+h);
float ar=s*(s-l)*(s-b)*(s-h);
float area;
int ch;
cout<<"How do you want to calculate the area?"<<endl;
cout<<"1) simple formula"<<endl<<"2) heron's formula"<<endl;
cin>>ch;
if(ch==1){
cout<<"Enter the sides of the triangle."<<endl;
cin>>l>>b>>h;
area=0.5*(b*h);
cout<<"Area of the triangle is = "<<area<<endl;
}
else if (ch==2){
cout<<"Enter the sides of the triangle."<<endl;
cin>>l>>b>>h;
cout<<s<<endl<<l+b+h<<endl;
cout<<"The calculated area of the triangle is = "<<sqrt(ar)<<endl;
}
return 0;
}
It prints the correct value for l+b+h but, for s, it displays a huge negative number .I've tried changing the data type of s too. This happens in almost all my programs.