Answer to Question #167662 in C++ for sara

Question #167662

Write a program that takes an integer input from the user. The program should print if the integer is positive or negative. (a) Write another program for the same purpose but the program should say if the integer is positive, negative or zero.


1
Expert's answer
2021-03-01T16:03:03-0500
#include <iostream>
using namespace std;

int main() {
	cout << "Enter a number: ";
	int number;
	cin >> number;
	if (number > 0)
		cout << "Positive";
	if (number < 0)
		cout << "Negative";
}

Another program, with zero:

#include <iostream>
using namespace std;

int main() {
	cout << "Enter a number: ";
	int number;
	cin >> number;
	if (number > 0)
		cout << "Positive";
	if (number < 0)
		cout << "Negative";
	if (number == 0)
		cout << "Zero";
}

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