Program for a right Triangle

I need help with this...this is my fourth week in C++ online class, and it is going pretty bad. There are some errors on my code, mainlly where the equal signs are, and the declared sides. take a look. I would appreciate any help.

// Russell_Glen_Lab2_2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{

float side1 = 5.0;
float side2 = 4.0;
float side3 = 3.0;

cout << "Enter the side of the angle you want to solve";
cin >> side1 >> side2 >> side3;
cin >> side1 = (pow(side2,2) + pow(side3,2)) endl;
cin >> side2 = (pow(side1,2) - pow(side3,2)) endl;
cin >> side3 = (pow(side1,2) - pow(side2,2)) endl;

if (side1 < 0 && side2 < 0 && side3 < 0) //False means that triangle is not right triangle
return false; // true means triangle is right triangle
else if (side2 + side3 = side1 || side1 - side3 = side2 || side1 - side2 = side3)
return true;

else return false;

system ("pause")


return 0;
}
Well, "=" is the assignment operator, and "==" checks if an expression is true". So in your line:

else if (side2 + side3 = side1 || side1 - side3 = side2 || side1 - side2 = side3)

you need to replace the "=" with "==". Another problem you are having is getting input. You use cin 4 times, when you only need it once.

1
2
3
4
5
cout << "Enter the side of the angle you want to solve";
cin >> side1 >> side2 >> side3;
cin >> side1 = (pow(side2,2) + pow(side3,2)) endl;
cin >> side2 = (pow(side1,2) - pow(side3,2)) endl;
cin >> side3 = (pow(side1,2) - pow(side2,2)) endl;


I think you want to be using cout instead of cin for those last 3 lines.
Bluehailex...thank you, I changed the last cin lines to cout <<, and changed the equal signs to the conditional logig of ==. That got rid of just about all of my errors. I am still having a problem with the equal signs in the equation area...anything look wrong there? here is the new code:


#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{

float side1 = 5.0;
float side2 = 4.0;
float side3 = 3.0;

cout << "Enter the side of the angle you want to solve";
cin >> side1 >> side2 >> side3;
cout << side1 = (pow(side2,2) + pow(side3,2));
cout << side2 = (pow(side1,2) - pow(side3,2));
cout << side3 = (pow(side1,2) - pow(side2,2));

if (side1 < 0 && side2 < 0 && side3 < 0) //False means that triangle is not right triangle
return false; // true means triangle is right triangle
else if (side2 + side3 == side1 || side1 - side3 == side2 || side1 - side2 == side3)
return true;

else return false;

system ("pause")


return 0;
}

I thought I declared everything...but the equal signs in the declaration eqns are still red.
cout << side1 = (pow(side2,2) + pow
(side3,2));

where is "..." ?

cout <<" side1 = " << (pow(side2,2) + pow
(side3,2));
1
2
3
4
5
cout << "Enter the side of the angle you want to solve";
cin >> side1 >> side2 >> side3;
cin >> side1 = (pow(side2,2) + pow(side3,2)) endl;
cin >> side2 = (pow(side1,2) - pow(side3,2)) endl;
cin >> side3 = (pow(side1,2) - pow(side2,2)) endl;

These 3 lines don't make sense and side1 is not equal to side2^2 plus side3^2 etc.
side1==sqr(side2^2+side3^2)
if (side1 < 0 && side2 < 0 && side3 < 0) //False means that triangle is not right triangle

This means that each side is negative
1
2
else if (side2 + side3 = side1 || side1 - side3 = side2 || side1 - side2 = side3)
return true;

This is also incorrect for the same reasons as explained above
Topic archived. No new replies allowed.