Answer to Question #185975 in C++ for Mridul

Question #185975
Write an if else statement using a Boolean expression to test whether exactly one of two
integers is zero. Assume x, y are variables of type int and are declared and initialized.
The if block should print the following message: Exactly one of x or y is zero and the
else block should print: Neither or both of x and y are zero.
1
Expert's answer
2021-04-30T05:39:06-0400
#include <iostream>
using namespace std;


int main(){
	int a, b;
	cout << "Enter the value of a" << endl ;
	cin >> a;
	cout << "Enter the value of b" << endl;
	cin >> b;
    // applying conditions 
	if ((a != 0 and b==0) or (a == 0 and b !=0)){
		cout << "Exactly one of x or y is zero" << endl;
	}
	else{
		cout << "Neither or both of x and y are zero" << endl;
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS