' ' 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::answer = 0.5*(h*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;
}
Indeed answer is not a part of the std namspace, change std::answer to answer:

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 !!
And Please use code tags

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

double answer = 0.5*(h*b);

instead of

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:

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <cmath>
#include <iomanip>

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";
}

1
2
3
4
5
6
7
8
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.
https://play.google.com/store/apps/details?id=com.ustwo.monumentvalley&hl=en_US&gl=US
If'n one uses the Steam gaming front end Monument Valley is available as well as a sequel in panoramic editions.

Whatever "panoramic edition" means for these games. ¯\_(ツ)_/¯

https://store.steampowered.com/bundle/25548/Monument_Valley_Panoramic_Collection/

Monument Valley is ethereal - quiet delivering good vibes. One of its pros is the astonishing aesthetic. Great. Thanks for the links.
Also I like Antichamber ++
Topic archived. No new replies allowed.