So, I am required to make something that adds and substracts two 16 digit numbers, each of them composed of two 8 digit numbers respectively.
This needs to be done using integers only and using only If, switch or for.
what I have till now is this
using namespace std;
int number1l, number1r, number2l, number2r;
int suml, sumr, diffl, diffr;
cout << "number 1:";
cin >> number1l >> number1r;
cout << "number 2:";
cin >> number2l >> number2r;
suml = number1l + number2l;
sumr = number2r + number2r;
diffl = number1l - number2l;
diffr = number2r - number2r;
if (sumr > 99999999)
else if (diffr < 99999999)
cout << setfill('0');
cout << "sum:" << setw(8) << suml << setw(8) << sumr;
cout << "diff" << setw(8) << diffl << setw(8) << diffr;
It all goes fine but somehow in the end I end up getting wrong calculations.
If i put 11111111 11111111 and 22222222 22222222
i get 3333333344444444 as sum and 1111111210000000 as difference.
What am i doing wrong here, any help would be appreciated.
Edit: Nevermind, found out what was wrong :/