User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,857 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,631 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1785 | Replies: 3
Reply
Join Date: Sep 2004
Posts: 20
Reputation: dcving is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
dcving's Avatar
dcving dcving is offline Offline
Newbie Poster

Using while statement..any suggestions?

  #1  
Nov 6th, 2004
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;
		}
Last edited by alc6379 : Nov 7th, 2004 at 4:35 pm. Reason: added [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2004
Posts: 44
Reputation: jigvesh is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jigvesh jigvesh is offline Offline
Light Poster

Re: Using while statement..any suggestions?

  #2  
Nov 6th, 2004
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;
		}
Last edited by alc6379 : Nov 7th, 2004 at 4:35 pm. Reason: added [code] tags
Reply With Quote  
Join Date: Sep 2004
Posts: 20
Reputation: dcving is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
dcving's Avatar
dcving dcving is offline Offline
Newbie Poster

Re: Using while statement..any suggestions?

  #3  
Nov 6th, 2004
Oh... That makes it less complicated.. Thank you Jigvesh
Reply With Quote  
Join Date: Sep 2004
Posts: 6,340
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 29
Solved Threads: 460
Super Moderator
Narue's Avatar
Narue Narue is online now Online
Expert Meanie

Re: Using while statement..any suggestions?

  #4  
Nov 6th, 2004
>while (Number1 >> 0) {
"While the number is much greater than zero"? A bitwise shift doesn't appear to be something you would want in this program.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 3:31 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC