Ok... There are a few things that you could work on with your code.
First of all the basics: Here is what I got when I typed in 2 and 6.
Exact Copy:
___________________________________
2 is less than6
2 is less than or equal to 6
2 is an even number
6 is an even number
The difference between 2 and 6 is -4.
2 divided by 6 is 0
6 divided by 2 is 3
To Continue press y
____________________________________
Line (1) 2 is less than6
space the six out
Line (2) 2 is less than or equal to 6
we don't need to know this since the first line
just told us that it was less than, and it's not
equal too.
Line(3) 2 is an even number
Good
Line(4) 6 is an even number
Good
Line(5) The difference between 2 and 6 is -4.
Here's a little piece of code that will fix that problem:
- Code: Select all
if (number < 0)
{
number *= -1;
}
Line(6) 2 divided by 6 is 0
This is wrong, but because you used int
it comes out this way. Try using double,
that way it will come out with a decimal number.
Or because the assignment was to make it with
integers, you could check to see which one was bigger,
whatever one ended up to be bigger then that one
was the one that would the base of the division.
Line(6)6 divided by 2 is 3
This is good
Line(10) To Continue press y
Good
______________________________________________________
That was the machanics behind your code.
The next thing I want to talk about is why does it look the way it
does in the compiler. This may seem stupid to talk about but it is key
if your ever going to work on a project with multiple people
or even share your code with others like your doing now.
When you are typing in the compiler you will notice that it does many things for you. The main things are it indents lines and it colors words. There are a few purposes to this but the main thing is for organization.
After every opening bracket the next line gets indented another
few spaces. This is to show you bits of code. You should have all
your brackets end up so that the return statement is right at the end where it is suppose to be. If you look at your code. It's way out there.
So even though your code runs, when people look at it, it will take them
twice as long to figure out where things are, and whats happening because they're used to the standard way of indenting lines which you seemed to ignore here. I fixed up the code, just the orginization part. I want you and others to see how much it helped from the last code you posted.
- Code: Select all
#include<iostream>
using namespace std;
int main ()
{
system("TITLE Project 2");
system("COLOR 4");
int iNum1;
int iNum2;
char exit;
bool bExit = true;
while(bExit == true)
{
cout << " Please enter an interger number " <<endl;
cin >> iNum1;
cout << " Please enter a second integer number " <<endl;
cin >> iNum2;
if (iNum1 == iNum2)
{
cout << iNum1 << " is " << " equal to " << iNum2 <<endl;
}
if (iNum1 < iNum2)
{
cout << iNum1 << " is less than" << iNum2 <<endl;
}
if (iNum1 > iNum2)
{
cout << iNum1 << " is greater than " << endl <<endl;
}
if (iNum1 <= iNum2)
{
cout << iNum1 << " is less than or equal to " << iNum2 <<endl;
}
if (iNum1 >= iNum2)
{
cout << iNum1 << " is greater than or equal to " << iNum2 <<endl;
}
if ((iNum1 % 2) ==0 )
{
cout << iNum1 << " is an even number " << endl;
}
else
{
cout << iNum1 << "is a negative number " << endl;
}
if ((iNum2 % 2) == 0 )
{
cout << iNum2 << " is an even number " <<endl;
}
else
{
cout << iNum2 << " is an odd number " << endl << endl;
}
cout << " The difference between " << iNum1 << " and " << iNum2 << " is " << iNum1-iNum2 << endl;
cout << iNum1 << " divided by " << iNum2 << " is " << iNum1/iNum2 << endl <<endl;
cout << iNum2 << " divided by " << iNum1 << " is " << iNum2/iNum1 << endl <<endl;
cout << " To Continue press y " << endl;
cin >> exit;
if (exit == 'y' )
{
bExit = true;
}
else
{
bExit = false;
}
}//while
return 0;
}
I am in no way ripping on you. This was an excellent attempt to build an
integer statistic application. Great Job, your code just needed a few little things. Other then that. You did Great!

I'm a 15 year old kid who has his heart set on Programming.
Came here hoping to help so if you have any questions just ask!