Using while statement..any suggestions?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2004
Posts: 20
Reputation: dcving is an unknown quantity at this point 
Solved Threads: 0
dcving's Avatar
dcving dcving is offline Offline
Newbie Poster

Using while statement..any suggestions?

 
-1
  #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?

  1. /* Program description: Create a program that prompts for two integer values.
  2. The program will display whether the integers are either:
  3. - and +, + and +, or - and -, or 0.
  4. Author: Eric Martin
  5. Date: 8 November 2004 */
  6.  
  7. #include <iostream>
  8. #include <conio.h>
  9. using namespace std;
  10.  
  11. int main (){
  12. int Number1;
  13. int Number2; // Declare integers
  14. int Zero = 0;
  15.  
  16. cout << "USING POSITIVES AND NEGATIVES!";
  17. cout << endl;
  18. cout << endl;
  19. cout << "Please enter the first number: ";
  20. cin >> Number1;
  21. cout << "Please enter the second number: ";
  22. cin >> Number2;
  23. cout << endl;
  24.  
  25. while (Number1 >> 0) {
  26. if (Number1 > 0)
  27. cout << Number1 << " is a positive number!";
  28. if (Number1 < 0)
  29. cout << Number1 << " is a negative number!";
  30. break;
  31. }
  32. cout << endl;
  33.  
  34. while (Number2 >> 0) {
  35. if (Number2 > 0)
  36. cout << Number2 << " is a positive number!";
  37. if (Number2 < 0)
  38. cout << Number2 << " is a negative number!";
  39. break;
  40. }
  41.  
  42.  
  43. getch ();
  44. return 0;
  45. }
Last edited by alc6379; Nov 7th, 2004 at 5:35 pm. Reason: added [code] tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 44
Reputation: jigvesh is an unknown quantity at this point 
Solved Threads: 0
jigvesh jigvesh is offline Offline
Light Poster

Re: Using while statement..any suggestions?

 
-1
  #2
Nov 6th, 2004
HEY WHY DONT YOU FORGET THE WHILE LOOPS. THE CODE BELOW GIVES U THE DESIRED OUTPUT

  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4.  
  5. int main (){
  6. int Number1;
  7. int Number2; // Declare integers
  8. int Zero = 0;
  9.  
  10. cout << "USING POSITIVES AND NEGATIVES!";
  11. cout << endl;
  12. cout << endl;
  13. cout << "Please enter the first number: ";
  14. cin >> Number1;
  15. cout << "Please enter the second number: ";
  16. cin >> Number2;
  17. cout << endl;
  18.  
  19. if (Number1 > 0)
  20. cout << Number1 << " is a positive number!";
  21. else if (Number1 < 0)
  22. cout << Number1 << " is a negative number!";
  23. else
  24. cout << Number1 << " is ZERO!";
  25.  
  26. cout << endl;
  27.  
  28. if (Number2 > 0)
  29. cout << Number2 << " is a positive number!";
  30. else if (Number2 < 0)
  31. cout << Number2 << " is a negative number!";
  32. else
  33. cout << Number2 << " is ZERO!";
  34.  
  35.  
  36. getch ();
  37. return 0;
  38. }
Last edited by alc6379; Nov 7th, 2004 at 5:35 pm. Reason: added [code] tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 20
Reputation: dcving is an unknown quantity at this point 
Solved Threads: 0
dcving's Avatar
dcving dcving is offline Offline
Newbie Poster

Re: Using while statement..any suggestions?

 
0
  #3
Nov 6th, 2004
Oh... That makes it less complicated.. Thank you Jigvesh
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Using while statement..any suggestions?

 
0
  #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 here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC