Considering you've already done the midterm i think its justified to post my version of it. I'd be interested to know if its close to the actual answer.
Code:
#include <iostream>
using namespace std;
int main() {
const int size = 6;
int nums[size];
cout << "Enter 6 numbers:\n";
for (int i = 0; i < size; i++) {
cout << (i + 1) << ":> ";
cin >> nums[i];
}
for (int i = 0; i < size - 3; i++)
for (int j = i + 1; j < size - 2; j++)
for (int k = j + 1; k < size - 1; k++)
if ((nums[i] + nums[j] + nums[k]) == nums[size-1]) {
cout << "Yes: ";
cout << nums[i] << " + ";
cout << nums[j] << " + ";
cout << nums[k] << " = ";
cout << nums[5] << "\n";
}
return 0;
}
As you can see its pretty close to the functionality given in the spec but if there are no matches, it won't say "No." it'll just end. Also, it'll list all matching combinations that add up to nums[5].