| | |
Using while statement..any suggestions?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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?
C++ Syntax (Toggle Plain Text)
/* 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 5:35 pm. Reason: added [code] tags
•
•
Join Date: Oct 2004
Posts: 44
Reputation:
Solved Threads: 0
HEY WHY DONT YOU FORGET THE WHILE LOOPS. THE CODE BELOW GIVES U THE DESIRED OUTPUT
C++ Syntax (Toggle Plain Text)
#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 5:35 pm. Reason: added [code] tags
![]() |
Similar Threads
- wrong number of parameters sqlstate=07001 (C#)
- SQL query program to edit records (MySQL)
- join in select statement (Visual Basic 4 / 5 / 6)
- Any suggestions or help will be appreciated…ASAP! (ASP)
- need help with an IF statement (C++)
Other Threads in the C++ Forum
- Previous Thread: Help with assignment
- Next Thread: Mathematical formulas used in C++ ?
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets








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