Your Solution works well but is not dynamic enough.
For example, if we change the number of elements in the nums array, everything will vary and get different results. I mean that the 70 won't be on index 3 all the time.
Keep in mind that, if the first number isn't bigger than the check number, so check on the second and third numbers, and so on.
I know that Elzero didn't ask for all of this, but consider it a challenge to improve your way of thinking, why not? 😄
I figured out the dynamic solution, but I want you to try and solve it on your own.
Maybe I can send the solution after you give up. 😂
Of course, the code would be better if we had used functions, but we haven't reached functions lessons yet.
Here are some test cases to ensure that your code is dynamic:
#include <iostream>
using namespace std;
int main()
{
// Please uncomment the first 2 lines in a test case of your choice and then run the code (as in test case 4).
// Make sure that only 1 test case is uncommented.
// === Test Case 1 ===
// int check = 14;
// int nums[]{21, 10, 6, 79, 100};
// Output:
// "{21} + {79} = 100"
// === Test Case 2 ===
// int check = 25;
// int nums[]{15, 35, 20, 70, 100};
// Output:
// "{35} + {70} = 105"
// === Test Case 3 ===
// int check = 32;
// int nums[]{20, 25, 35, 75, 100};
// Output:
// "{35} + {75} = 110"
// === Test Case 4 ===
int check = 10;
int nums[]{20, 25, 35, 75, 100};
// Output:
// "{20} + {75} = "95"
// "{25} + {75} = 100"
// "{35} + {75} = 110"
// === Test Case 5 ===
// int check = 20;
// int nums[]{25, 30, 15, 60, 100};
// Output:
// "{25} + {60} = "85"
// "{30} + {60} = "90"
// === Test Case 6 ===
// int check = 16;
// int nums[]{20, 12, 35, 55, 100};
// Output:
// "{20} + {55} = "75"
// "{35} + {55} = "90"
// === Test Case 7 ===
// int check = 30;
// int nums[]{20, 32, 35, 90, 100};
// Output:
// "{32} + {90} = "122"
// "{35} + {90} = "125"
// === Test Case 8 ===
// int check = 50;
// int nums[]{20, 32, 35, 90, 100};
// Output:
// "Sorry, The first 3 numbers are smaller than or equal to 50"
// Write Your Condition Here
return 0;
}
Think dynamically, brother.
Contact me if need be.
Good Luck
Your Solution works well but is not dynamic enough.
For example, if we change the number of elements in the
numsarray, everything will vary and get different results. I mean that the70won't be onindex 3all the time.Keep in mind that, if the first number isn't bigger than the
checknumber, so check on the second and third numbers, and so on.I know that Elzero didn't ask for all of this, but consider it a challenge to improve your way of thinking, why not? 😄
I figured out the dynamic solution, but I want you to try and solve it on your own.
Maybe I can send the solution after you give up. 😂
Of course, the code would be better if we had used functions, but we haven't reached functions lessons yet.
Here are some test cases to ensure that your code is dynamic:
Think dynamically, brother.
Contact me if need be.
Good Luck