advice on mods to be done.... here is a short version of this prog i'm writing, but there is a prob.... what changes should i make??
# include %26lt;iostream%26gt;
using namespace std;
int main()
{
int x,y;
cout%26lt;%26lt;%26quot;enter two integer numbers%26quot;%26lt;%26lt;endl;
cin%26gt;%26gt;x%26gt;%26gt;y;
if(x %26amp;%26amp; y %26gt; 0)
cout%26lt;%26lt;%26quot;all numbers are positive%26quot;%26lt;%26lt;endl;
else cout%26lt;%26lt;%26quot;not all numbers are positive%26quot;%26lt;%26lt;endl;
}
it doesnt work when i put a neg number..... it keeps printing out the%26quot;all numbers are positive....
oh...and the numbers have to be integers
Guys.... i come again in peace.... always wanted to say that.... well i need help with this program....?
The problem is on the line
if (x %26amp;%26amp; y %26gt; 0)
This line doesn't do what you think it does. What you meant to say was %26quot;if (x %26gt; 0 %26amp;%26amp; y %26gt; 0)%26quot;. The %26amp;%26amp; seperates distinct operations, so the compiler sees it as %26quot;If (x) and if (y %26gt; 0)%26quot;. What this literally means is %26quot;If x is not zero y %26gt; 0%26quot;.
Good luck.
PS----
C++ is not a low-level language (C is more so, but not C++) and it's really not that hard. The error you made here would be 100% the same in C#, Java, Python, Visual Basic, etc.
Never ever let anyone scare you away from C++ because it's %26quot;hard.%26quot; It's no harder than any other language... the only difference is that you encounter the difficulty sooner.
Rant over.
Guys.... i come again in peace.... always wanted to say that.... well i need help with this program....?
Here is full, working program...
# include %26lt;iostream%26gt;
using namespace std;
int main()
{
int x,y;
cout%26lt;%26lt;%26quot;Enter two integer numbers%26quot;%26lt;%26lt;endl;
cin%26gt;%26gt;x%26gt;%26gt;y;
if(x %26gt; 0 %26amp;%26amp; y %26gt; 0)
{
cout%26lt;%26lt;%26quot;All numbers are positive%26quot;%26lt;%26lt;endl;
}else{
cout%26lt;%26lt;%26quot;Not all numbers are positive%26quot;%26lt;%26lt;endl;
}
}
You are clearly very new to programming. As I do with everyone trying to learn C++, I will tell you to stop immediately. C++ is a very low level language, and not a good language to start of with.
If you wish to follow my advice, I would recommend you check out the free version of dark basic professional. Its an easy to learn language, whilst being powerful, it has great help files and a good community to help you.
If you're interested you can go to http://darkbasicpro.thegamecreators.com/ and download the free version, or you can contact me by email or IM at karljacques95@msn.com
Thanks.
Good advice Karl, but this person is most likely taking a course in C++ in college.
Asker: Pay more attention in class and study your book more.