So I am trying to do a simple subtraction problem where the larger number would go first so the difference can be a positive or zero, but I am stump. If I just remove the if and else with either x - y or y - x it would work. It is something in my function from what it seems.
Code:#include <iostream>
using namespace std;
int sub ( int x, int y );
int main()
{
int x;
int y;
cout<<"We will subtract two numbers and it will always be positive or zero.";
cin.ignore();
cout<<"Please input two numbers: ";
cin>> x >> y;
cin.ignore();
cout<<"The difference is "<< sub ( x, y ) <<"\n";
cin.get();
}
int sub ( int x, int y )
{
if ( x < y ) {
return y - x;
}
else ( x > y ) {
return x - y;
}
}