•
•
•
•
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
![]() |
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
•
•
Join Date: Oct 2004
Posts: 44
Reputation:
Rep Power: 0
Solved Threads: 0
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- my computer will not boot (Windows NT / 2000 / XP / 2003)
- Any suggestions or help will be appreciated…ASAP! (ASP)
- Forcing an Exit From PHP (PHP)
- system("PAUSE") (C++)
- need help with an IF statement (C++)
- Reading MSWord Document through an ASP Statement (ASP)
- Offer me your suggestions (Troubleshooting Dead Machines)
- Configuration opinions/suggestions... (Troubleshooting Dead Machines)
Other Threads in the C++ Forum
- Previous Thread: Help with assignment
- Next Thread: Mathematical formulas used in C++ ?




A bitwise shift doesn't appear to be something you would want in this program.
Linear Mode