The if loop doesn't work and i don't know how to fix it, i have to verify the entered numbers read from the KBD to see if they can form a triangle, but it's not working as it should.. I wrote the code in Visual Studio 2019, separately in a header file and a source file.
#include<iostream>
using namespace std;
class Triangle
{
protected:
int a, b, c;
public:
Triangle(int x = 0, int y = 0, int z = 0)
{
a = x;
b = y;
c = z;
}
float perim()
{
return (a + b + c) / 2;
}
};
class Triangle_extended :public Triangle //derived class in public method
{
public:
Triangle_extended(int x, int y, int z) :Triangle(x, y, z) {}
float area()
{
float p;
p = perim();
return sqrt(p * (p - a) * (p - b) * (p - c));
}
};
The problem looks like is in the main(), but i don't know where Also, when i use ob1 to find the perimeter, it gives 0 all the time, if i use ob2 for that too it gives the correct value. I have to make it work with object 1
#include"Header.h"
int main()
{
int a, b, c;
Triangle ob1; //object for the base class
cout << "Enter 3 sides:";
cin >> a >> b >> c;
if ((a + b > c) || (a + c > b) || (b + c > a))
{
Triangle_extended ob2(a, b, c); //object for the derived class
cout << "\nPerimeter is:" << ob1.perim();
cout << "\nArea is:" << ob2.area();
}
else
cout << "\nNumbers can't form a triangle!";
}