Q: C++ Returning Wrong Line of Code I was instructed to design an algorithm that would allow the user to calculate the perimeter and area of a rectangle, but that's too easy:
Perimeter = 2 (Length + Width)
Area = (Length * Width)

I wanted to build a program using a similar construction to one my professor showed us on the first day so that I could have a program collect data from the user, calculate the perimeter and area of the rectangle for me, and then output the answer back to the user. That was easy enough, so I decided I wanted the program to also tell me whether or not the length and width that the user entered was the length and width of a rectangle or a square.
With the code I wrote, the program always returns that the length and width entered are the length and width of a square. I am not sure where I went wrong:
Here is my code:
#include<iostream>
using namespace std;

int main() {

    //Declaration
    int length;
    int width;
    int perimeter;
    int area;

    //Collect Data
    cout << "Let's calculate the perimeter and area of a rectangle\n";
    cout << "What is the length of the rectangle?: ";
    cin >> (length);

    cout << "What is the width of the rectangle?: ";
    cin >> (width);

    //Calculation
    (perimeter) = 2 * (length + width);
    (area) = (length) * (width);

    //Output Data
    cout << "The perimeter of the rectangle is: " << (perimeter) << "\n";
    cout << "The area of the rectangle is: " << (area) << "\n";

    //For some reason, the code is not able to recognize what I have designed.
    //No matter what input for length and width, when the program executes it returns that I entered the length and width of a square.
    if ((length) = (width))
        cout << "Hey! You entered the length and width of a Square!\n";
    else
        cout << "You entered the length and width of a Rectangle!\n";

    system("pause");
    return 0;

}

Any help would be greatly appreciated! Thank you so much!

A: You want a double equals:
if (length == width)

A single equals (=) performs assignment, double equals (==) performs a comparison.

A: In your if-statement you are assigning width to length, not comparing.
It should be: if (length == width)
The reason why your if-statement evaluates to true is because it checks whether the result of the evaluation (which is the value of length) is different from zero.
That's because a bool is internally represented as an int, where false is defined as 0 and true else.
And since width is usually not 0 it would always result in true. 
You can test it out by entering 0 for width.

A: One thing I would recommend is looking into using a debugger to step through each line of your code as it runs one at a time. If you are using VS you have one built right in!
I think if you used a debugger you would have noticed that when the if was running it was doing the assignment rather than the comparison. Just a thought for the future. 
I'm sure everyone can say they have caught many silly bugs with a debugger. Good job :)
