- Jul 29, 2004
- 5,830
- 5
- 81
Ok, I need help with the program I am writing, it calculates the area and perimeter of a triangle given sides a & b. Here is what I have so far (in C++):
# include <iostream>
using namespace std;
int main ()
{
float a;
float b;
float c;
float area;
float perimeter;
cout << "This program finds the perimeter and area of a triangle." << endl;
cout << "Enter the value for side a. ";
cin >> a;
if (a <= 0)
{
cout << "Bad Data.";
}
cout << "Enter the value for side b. ";
cin >> b;
if (b <= 0)
{
cout << "Bad Data.";
}
c = square((a*a)+(b*b));
perimeter = (a+b+c);
area = (1/2)*(a*b);
cout << "The perimeter of the triangle is " << perimeter;
cout << "The area of the triangle is: " << area;
system("pause");
return 0;
}
I know I need to add something like "# include <math>" or something like that so I can use the square root input.
What I need help with is that everytime I try to build the program, it doesnt find "c, or perimeter". What is the problem, and if there are any other problems with the code, what should I do. Please help, tooters are closed at 11 pm and no one in my dorm is in Comp Science and assignment is due tomorrow at 8 am.
# include <iostream>
using namespace std;
int main ()
{
float a;
float b;
float c;
float area;
float perimeter;
cout << "This program finds the perimeter and area of a triangle." << endl;
cout << "Enter the value for side a. ";
cin >> a;
if (a <= 0)
{
cout << "Bad Data.";
}
cout << "Enter the value for side b. ";
cin >> b;
if (b <= 0)
{
cout << "Bad Data.";
}
c = square((a*a)+(b*b));
perimeter = (a+b+c);
area = (1/2)*(a*b);
cout << "The perimeter of the triangle is " << perimeter;
cout << "The area of the triangle is: " << area;
system("pause");
return 0;
}
I know I need to add something like "# include <math>" or something like that so I can use the square root input.
What I need help with is that everytime I try to build the program, it doesnt find "c, or perimeter". What is the problem, and if there are any other problems with the code, what should I do. Please help, tooters are closed at 11 pm and no one in my dorm is in Comp Science and assignment is due tomorrow at 8 am.
