Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Problem with Int Function output (http://www.go4expert.com/forums/int-function-output-t19977/)

Towely 4Nov2009 10:06

Problem with Int Function output
 
I'm having a problem with the output of my program.

The "SumFunction" function adds the digits of a number together. For instance, the number 4532 would be 4 + 5 + 3 +2 and the output would equal 14.
the rest of the program determines if the last digit of the "SumFunction" of 2 user-given numbers are the same. If so, they are "Sum Buddies". The problem is that the code always says that any two numbers are Not Sum Buddies, even if they actually are.

It's a fairly simple code... Where am I going wrong?

Code:

#include <iostream>
using namespace std;

int SumFunction (int x)
{
  int result = 0;
  result = ((x % 10) + ((x / 10) % 10) + ((x / 100) % 10) + ((x / 1000) % 10) + ((x / 10000) % 10));
  return (result);

}

int main ()
{
  int a, b;
  cout << "Type Two Numbers: ";
  cin >> a >> b;

  if ((SumFunction(a) % 10) == (SumFunction(b) % 10))
  {
      cout << a << " and " << b << " are sum pals." << endl;
  }
  else
      cout << a << " and " << b << " aren't sum pals." << endl;


Towely 4Nov2009 10:17

Re: Problem with Int Function output
 
EDIT: The program worked fine all along. I was just using incorrect input! Sorry, you can delete this thread.


All times are GMT +5.5. The time now is 14:02.