need help about c++ add two different size arrays

I cant get the output that i want,please help me.
i want the program can show the number it choose.and the array size must be different.(my fd said that the array must be same)
Many thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  #define _USE_MATH_DEFINES 
#include <iostream> 
#include <iomanip>
using namespace std;

int main()
{

	int sum;

	do
	{
		cout << "Enter the sum (0 to 7, 0 to exit):"; 
		cin >> sum;

		if (cin.fail())
		{
			cout << "Enter a number! " << endl;
			cin.clear();
			cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
		}

		if (sum == 0)
	  {
		cout << "END OF PROGRAM" << endl;

		return 0;
	  }

	} while (sum < 0 || sum > 7);



		double num1[4] = {0,1,2,3};
		double num2[2] = {0,4};

	

		
		sum =num1 +num2;
		

		cout << num1 << endl;
		cout << num2 << endl;


}
Last edited on
What do you want your sum to be?
i want my sum(input) is 0 to 7(0 to exit)
that the program can pick the number in two array to sum for me.

for example when i input 5
that it will pick 1 from first array and 4 from second array.And i want it show which number it picked from those arrays.
1
2
3
4
double num1 = sum >= 4? 4 : 0;
double num2 = sum >=4 ? sum - 4 : sum;

std::cout << num1 << '\n' << num2;
Is this a:
Select x from set A and y from set B so that x+y==sum.

Pseudo:
1
2
3
4
5
6
7
for ( auto x : A ) {
  auto y = sum - x;
  if ( B contains y ) {
    return success (x,y)
  }
}
return failure
Topic archived. No new replies allowed.