Hello guys!
Basically I have this basic homework, the program must check if the digit sum of one of the 3 inputted integers is equal to the difference of 2 others. So if A = 56, B = 33 and C = 22, the program should output 56, cause 5+6 = 33 - 22. I think I have the code but I can`t find whats wrong, it always says that such number is not found even tho it should be. Thanks!
#include <iostream>
using namespace std;
int main()
{
int a, b, c, suma = 0, sumb = 0, sumc = 0, diga = 0, digb = 0, digc = 0, ok;
do
{
do
{
cout << "Input 3 integers" << endl;
cin >> a >> b >> c;
if (a <= 0 || b <= 0 || c <= 0)
{
cout << "You entered invalid data" << endl;
}
} while (a <= 0 || b <= 0 || c <= 0);
do
{
diga = a % 10;
suma+= diga;
a = a / 10;
} while (a > 0);
do
{
digb = b % 10;
sumb+= digb;
b = b / 10;
} while (b > 0);
do
{
digc = c % 10;
sumc+= digc;
c = c / 10;
} while (c > 0);
if (suma == b-c || suma == c-b)
{
cout << a << endl;
}
else if (sumb == a-c || sumb == c-a)
{
cout << b << endl;
}
else if (sumc == a-b || sumc == b-a)
{
cout << c << endl;
}
else
{
cout << "Does not exist" << endl;
}
cout << "Continue (1) or end (0)?" << endl;
cin >> ok;
} while (ok == 1);
return 0;
}