More than a couple of parenthesis are missing in your if statements.
I suggest you should:
- avoid declaring variables until you haven’t a value to store inside them;
- don't let any variable uninitialised;
- prefer double to float;
And, if possible:
- read compiler errors / warnings (they describe problems quite well);
- keep in mind operator precedence (precedence of ^ is lower the one of than ==, so perhaps you want to add some parenthesis, don’t you?)
http://en.cppreference.com/w/cpp/language/operator_precedence
- keep your code a bit tidier (you would have noticed the missing parenthesis by yourself).
Let’s look a code like the following:
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
|
#include <iostream>
int main()
{
std::cout << "care este valoarea laturii x a triunghiului? ";
double x = 0.0;
std::cin >> x;
std::cout << "care este valoarea laturii y a triunghiului? ";
double y = 0.0;
std::cin >> y;
std::cout << "care este valoarea laturii z a triunghiului? ";
double z = 0.0;
std::cin >> z;
if(x == y && y == z) {
std::cout << "triunghiul este echilateral.\n";
}
if((x == y) || (x == z) || (y == z)) {
std::cout << "triunghiul este isoscel.\n";
}
if( ((x^2) == (y^2) + (z^2))
|| ((y^2) == (x^2) + (z^2))
|| ((z^2) == (x^2) + (y^2)) ) {
std::cout << "triunghiul este dreptunghic.\n";
}
std::cin.ignore();
std::cin.get();
return 0;
}
|
In the above code are at least these errors:
a) you are comparing floating point numbers. It’s not a problem for the compiler, but in general you’d better avoid it. One of the many pages on this topic is:
http://floating-point-gui.de/errors/comparison/
In this case, however, since your are storing the numbers directly from the user and they don’t come from calculation, the comparison could be plausible (but I’d avoid it anyway).
b) You’re using the symbol ^ in a wrong context and, I suspect, without knowing its meaning in the C++ language.
Please, have a look here:
http://en.cppreference.com/w/cpp/language/operator_alternative
I think you were searching for the pow() function:
http://en.cppreference.com/w/cpp/numeric/math/pow