0

new guy in this sphere, dont bash too much :S

#include <iostream>
using namespace std;

int main()
{
	int x,y;
	cin>> x; cin>> y;

	if (x==0) cout<< "x = 0";
         else cout<< "x isnt 0";
		return 0;
}

this piece works ok but if i add 1 more condition it fails:

#include <iostream>
using namespace std;

int main()
{
	int x,y;
	cin>> x; cin>> y;
	if (x==0);(y==0); cout<< "x/y = 0";
		else cout<< "neither is 0";
		return 0;
}

i want it to check if either x or y equals 0
so what can be done about this?

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by Lensva
0

You write it like this:

int main()
{
  int x, y;
  cin >> x;
  cin >> y;
  if (x==0 && y==0)
  // the && means and, use || for or
  {
    cout << "x/y = 0";
  }
  else
  {
    cout << "neither is 0";
  }
  return 0;
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.