[c++] array
hi all, the question is:
write a program that inputs 6 integers,and then checks to see if any combination of exactly three of the first 5 integers adds up to the last integer.
test cases:
1)input -----> 1 -2 4 -1 15 17 output -------> Yes. -2+4+15=17
2) 3 12 11 -4 16 7 No.
It doesnt work though, any help would be appreciated.
this is what i have so far:
#include <iostream>
using namespace std;
int main()
{
const int size=6; //defines the size N for 6 elements
int a[6]; //declares the array's elements as integers
int i = 0;
cout << "Enter six numbers: ";
for (i=0;i<size;i++)
cin >> a[i];
for (i=0; i < 5;i++)
if ((a[i] + a[i+1] + a[i+2]) == a[5])
{
cout << "Yes." << a[i] << "+" << a[i+1] << "+" << a[i+2] << "=" << a[5];
}
else
cout << "No.";
return 0;
}
|