### ' ' is not a member of 'std'

I don't know how to fix this error
error : 'answer' is not a member of 'std'
#include <iostream>
#include <vector>
#include <string>

class Triangle{
private:
double totalAngle, angleA, angleB, angleC,h,b,area;
public:
Triangle(double A, double B, double C);
void setAngles(double A, double B, double C);
const bool validateTriangle();
};
Triangle::Triangle(double A, double B, double C) {
angleA = A;
angleB = B;
angleC = C;
totalAngle = A+B+C;
}
void Triangle::setAngles(double A, double B, double C) {
angleA = A;
angleB = B;
angleC = C;
totalAngle = A+B+C;
}

const bool Triangle::validateTriangle() {
return (totalAngle <= 180);
}
int main(){
double h,b,area;

std::cout <<"Enter the height of the triangle : ";
std::cin >> h;
std::cout <<"Enter the base of the triangle : ";
std::cin >> b;
std::cout.fixed;
std::cout.precision(2);
std::cout <<"The Area of the Triangle is : " <<answer;

//driver code
Triangle set1(40, 30, 110);

if(set1.validateTriangle()){
std::cout << "The shape is a valid triangle.\n";
} else {
std::cout << "The shape is NOT a valid triangle.\n";
}

return 0;
}

`double answer = = 0.5*(h*b);`

Although you probably meant `area` rather than answer. That code should be in a member function.

Try to avoid variable names like h, b. It is more meaningful to name the `height` and `base`.

Good Luck !!

https://cplusplus.com/articles/jEywvCM9/
The compiler is of course right. Guess you want this

`double answer = 0.5*(h*b);`

`std::answer = 0.5*(h*b);`
Thank you guys so much!!! I really appreciate your help :))
In the C++ programming language, the C++ Standard Library is a collection of classes and functions which are written in the core language and part of the C++ ISO Standard itself - and answer in your code does not belong them :) Using std (and its scope :: ) you can display text in the console (std::cout std::endl), you can use strings or vectors, pairs and more more more. This is the main base of C++

Take a look at the link below ++

https://en.wikipedia.org/wiki/C%2B%2B_Standard_Library

You can declare its namespace at the beginning of your program to save yourself writing each time std::

using namespace std;
Last edited on
 `` `` ``return (totalAngle <= 180);``

The sum of the angles of any triangle are exactly 180 degrees. If they sum to less or more than they are not angles of a triangle.

#However, as totalAngle is double doing an exact comparison with 180 is not guaranteed to be true even if the angles should add to 180 - due to the way non-integer numbers are represented in binary. The usual way to do such a comparison to check that the absolute value of num1 - num2 is less than a certain value (often called epsilon).

Consider:

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849`` ``````#include #include #include class Triangle { private: double totalAngle {}, angleA {}, angleB {}, angleC {}; public: Triangle(double A, double B, double C); void setAngles(double A, double B, double C); bool validateTriangle() const ; }; Triangle::Triangle(double A, double B, double C) { setAngles(A, B, C); } void Triangle::setAngles(double A, double B, double C) { angleA = A; angleB = B; angleC = C; totalAngle = A + B + C; } bool Triangle::validateTriangle() const { return std::fabs(totalAngle - 180.0) < 0.001; } int main() { double h {}, b {}; std::cout << "Enter the height of the triangle : "; std::cin >> h; std::cout << "Enter the base of the triangle : "; std::cin >> b; const auto area { 0.5 * (h * b) }; std::cout << std::fixed << std::setprecision(2) << "The Area of the Triangle is : " << area << '\n'; const Triangle set1(40, 30, 110); if (set1.validateTriangle()) std::cout << "The shape is a valid triangle.\n"; else std::cout << "The shape is NOT a valid triangle.\n"; }``````

 ``12345678`` ``````bool valid_triangle( double angle_A, double angle_B, double angle_C ) { static const double epsilon = 1.0e-6 ; return angle_A > epsilon && angle_B > epsilon && angle_C > epsilon && std::abs( (angle_A+angle_B+angle_C) - 180.0 ) < epsilon ; // note: for quiet floating-point comparisons, use std::isgreater, std::isless }``````
seeplus wrote:
The sum of the angles of any triangle are exactly 180 degrees. If they sum to less or more than they are not angles of a triangle.

That only applies to Euclidean space. A flat plane geometry.

The Real World isn't a flat plane, the Earth's an oblate spheroid. Transform a triangle drawn on that non-Euclidean surface to a Euclidean flat plane and the sum of the triangle's angles are greater than 180.

https://en.wikipedia.org/wiki/Non-Euclidean_geometry

In non-Euclidean space the sum of the 3 angles of a triangle equal more or less than 180 degrees depending on the curvature of the space. Euclidean space geometry is a localized approximation.

Define “triangle”.

Non-Euclidean space is just an excuse to bend Euclidean shapes in funny ways and measure them with the new geometries.

Or to pretend that triangles exist in Dalí-space.

So unless you’re playing with geosynchronous satellites or somesuch, a triangle’s angles still sum to 180°.
It doesn't really make sense to have a constructor of a triangle with 3 angles as parameters:
(a) because if you have two angles then the third angle is automatic from the requirement to sum to 180 degrees;
(b) because it still doesn't uniquely define the triangle (as you don't know its size).

The only ways that you could define (the possibility of) unique triangles (up to congruence) are:-
- three sides;
- two sides and an angle between them;
- two sides and an angle not between them;
- one side and two angles.
... and then you'd need a fourth parameter to distinguish which of those three-parameter choices you were using!
Last edited on
Hello. You started an interesting conversation about Non-Euclidean space. This subject is one of my favorites since I found a book with some Escher illustrations. Also I read an article about dimensions - which are always the projection of the previous (3D is the projection of the 2D, the 4D is the projection of the 3D, etc). So how many dimensions could exist? An infinity?
About the Non-Euclidean space, I would like (sorry for that) to recommend you ... a video game. No! A fabulous game - The Manifold Garden. The best artistic representation of the Non-Euclidean space. A must have.

However a triangle has always in our world perception 180° as angles sum.

https://en.wikipedia.org/wiki/M._C._Escher
https://store.steampowered.com/app/473950/Manifold_Garden

I forgot another game which has been created by an acquaintance of mine - a French guy from Paris. Fragments Of Euclid (for free). Great. If you are not a player, take a look at the video - and you have a clear perspective about what means a Non-Euclidean space ++

https://nusan.itch.io/fragments-of-euclid
Last edited on
Ah, yes, Monument Valley was one I particularly enjoyed.