So I have to solve this Problem: We assume that R1, R2, R3, and R4 have an integer valued resistance. After input of the four values, the program should output the result arithmetically rounded to the next integer. You may for this exercise assume that the builtin integer division rounds towards zero for all operands. Use of floating point arithmetic is not allowed. Changing to big number library is not possible.
and this is my code:
int R1;
int R2;
int R3;
int R4;
std::cin >> R1;
std::cin >> R2;
std::cin >> R3;
std::cin >> R4;
int R12 = R1 + R2;
int R34 = R3 + R4;
unsigned int Rtot = ((2*(R12 * R34) / (R12 + R34) + 1)) / 2 ;
std::cout << Rtot ;
return 0;
but if I use big numbers (8000 24000 16000 32000) I get a problem with the overflow. Any ideas? Doesn't work with unsigned, I tried. I'm guessing to solve it with modulus, but no idea how.