Everything works well, but I couldn't figure out how to use the else statement in case the user inputs 0 as a number..any comments/suggestions?

/* Program description: Create a program that prompts for two integer values. 
						The program will display whether the integers are either:
						- and +, + and +, or - and -, or 0.
	Author: Eric Martin
	Date: 8 November 2004 */

		#include <iostream>
		#include <conio.h>
		using namespace std;

		int main (){
			int Number1;
			int Number2;	// Declare integers
			int Zero = 0;
	
		cout << "USING POSITIVES AND NEGATIVES!";
		cout << endl;
		cout << endl;
		cout << "Please enter the first number: ";
		cin >> Number1;
		cout << "Please enter the second number: ";
		cin >> Number2;
		cout << endl;

		while (Number1 >> 0) {
		if (Number1 > 0)	
			cout << Number1 << " is a positive number!";
		if (Number1 < 0)
			cout << Number1 << " is a negative number!";
		break;
		}
		cout << endl;

		while (Number2 >> 0) {
		if (Number2 > 0)	
			cout << Number2 << " is a positive number!";
		if (Number2 < 0)
			cout << Number2 << " is a negative number!";
		break;
		}
		

		getch ();
		return 0;
		}
Dave Sinkula commented: Use code tags. +0

Recommended Answers

All 3 Replies

HEY WHY DONT YOU FORGET THE WHILE LOOPS. THE CODE BELOW GIVES U THE DESIRED OUTPUT

#include <iostream>
		#include <conio.h>
		using namespace std;

		int main (){
			int Number1;
			int Number2;	// Declare integers
			int Zero = 0;
	
		cout << "USING POSITIVES AND NEGATIVES!";
		cout << endl;
		cout << endl;
		cout << "Please enter the first number: ";
		cin >> Number1;
		cout << "Please enter the second number: ";
		cin >> Number2;
		cout << endl;

		if (Number1 > 0)	
			cout << Number1 << " is a positive number!";
		else if (Number1 < 0)
			cout << Number1 << " is a negative number!";
		else
			cout << Number1 << " is ZERO!";
	
		cout << endl;

		if (Number2 > 0)	
			cout << Number2 << " is a positive number!";
		else if (Number2 < 0)
			cout << Number2 << " is a negative number!";
		else
			cout << Number2 << " is ZERO!";
		

		getch ();
		return 0;
		}
commented: Use code tags. +0

Oh... That makes it less complicated.. Thank you Jigvesh

>while (Number1 >> 0) {
"While the number is much greater than zero"? :D;) A bitwise shift doesn't appear to be something you would want in this program.

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.