M
M
MPearson2021-07-11 12:46:25
C++ / C#
MPearson, 2021-07-11 12:46:25

Why does it show that the variables x, y, z are uninitialized? Why does it say that == is inappropriate and perhaps I meant =?

#include <iostream>
using namespace std;
int main() {
  int a, b, c, a1, b1, c1, x, y, z, x1, y1, z1;
  cin >> a >> b >> c >> a1 >> b1 >> c1;
  if (a >= b && b >= c) {
    x == a; y == b; z == c;
  }
  else if (a >= b && a >= c && c >= b) { x == a; y == c; z == b; }
  if (b >= a && a >= c) { x == b; y == a; z == c; }
  else if (b >= a && c >= a && b >= c) { x == b; y == c; z == a; }
  if (c >= a && a >= b) { x == c; y == a; z == b; }
  else if (c >= a && b >= a && c >= b) { x == c; y == b; z == c; }
  if (a1 >= b1 && b1 >= c1) {
    x1 == a1; y1 == b1; z1 == c1;
  }
  else if (a1 >= b1 && a1 >= c1 && c1 >= b1) { x1 == a1; y1 == c1; z1 == b1; }
  if (b1 >= a1 && a1 >= c1) { x1 == b1; y1 == a1; z1 == c1; }
  else if (b1 >= a1 && c1 >= a1 && b1 >= c1) { x1 == b1; y1 == c1; z1 == a1; }
  if (c1 >= a1 && a1 >= b1) { x1 == c1; y1 == a1; z1 == b1; }
  else if (c1 >= a1 && b1 >= a1 && c1 >= b1) { x1 == c1; y == b1; z1 == c1; }
  if (x - x1 == 0 && y - y1 == 0 && z - z1 == 0) {
    cout << "Boxes are equal";
  }
  else if (x - x1 > 0 && y - y1 > 0 && z - z1 > 0 || x - x1 > 0 && y - y1 == 0 && z - z1 == 0 || x - x1 == 0 && y - y1 == 0 && z - z1 > 0 || x - x1 > 0 && y - y1 > 0 && z - z1 == 0) {
    cout << "The first box is larger than the second one ";
  }
  else if (x - x1 < 0 && y - y1 < 0 && z - z1 < 0 || x - x1 < 0 && y - y1 == 0 && z - z1 == 0 || x - x1 == 0 && y - y1 == 0 && z - z1 < 0 || x - x1 > 0 && y - y1 < 0 && z - z1 == 0) {
    cout << "The first box is smaller than the second one";
  }
  else {
    cout << "Boxes are incomparable";
  }
  return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Shvedov, 2021-07-11
@MPearson

What did you want to do with this:

if (a >= b && b >= c) {
  x == a; y == b; z == c; // <-- ???
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question