Question: C++ Debug a function called SumBetween() which takes two integer inputs, low and high. This function should calculate the sum of all integers between low

 C++ Debug a function called SumBetween() which takes two integer inputs,
low and high. This function should calculate the sum of all integersC++

Debug a function called SumBetween() which takes two integer inputs, low and high. This function should calculate the sum of all integers between low and high inclusive Example: SumBetween(1,10) should return 55. SumBetween should throw std::invalid_argument if low and high are out of order SumBetween should throw std::overflow_error if the sum exceeds the maximum/minimum value of int. INT32_MAX is the maximum value of a 32-bit integer. INT32_MIN is the minimum value of a 32-bit integer. The function prototype is int SumBetween(int low, int high) Only use int. Don't use a bigger type (it can work, but is not in the spirit of the problem). HINT 1: Say a and b are two positive integers such that (a + b) results in an overflow. To form conditions for overflow_error, consider using subtraction expressions (INT32_MAX-a or INT32_MAX - b) instead of addition. Likewise, think about forming conditions with INT32_MIN. HINT 2. Can you readjust low and high so that you can avoid overflow during calculating the sum? For example, if low = INT32_MIN (-2147483648) and high = INT32_MAX (2147483647), values except -2147483648 do not need to be summed at all. START by correcting the syntax error(s), If any. 1- int SumBetween(int low, int high) { 2 int value 0; 3. for (int n low; n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!