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?

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;
}

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.