Can someone help me ?


Hello guys, I recently started to study the C++ language and my teacher gave me an assignment to write a code for a program.But I have a a problem.
SO what the program is supposed to do is to find the max element of an array and then to print out every 2 elements that are side by side from the array which sum is bigger than the max element.
This is what I have so far.
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
#include <iostream>
using namespace std;
int main()
{
	int n;
	float a[30], max;
	do {
		cout << "N=";
		cin >> n;

	} while (n < 2 || n >28);

	for (int i = 0; i <= n; i++)
	{
		cout << "a[" << i << "]=";
		cin >> a[i];
		
	}
	max = a[0];
	for (int i = 1; i <= n; i++)
	{	if (a[i] > max) max = a[i];
			if ((a[i] + a[i + 1]) > max);
			cout << "a[" << i << "]=" << a[i] << ", a[" << i + 1 << "]=" << a[i + 1] << endl;
		}
	
	system("pause");
	return 0;
}
You forgot to ask a question. What is your problem?

Also, What if n is like 50? The array cant take more than 30 elements. You got a problem there.

while (n < 2 || n >28);

You would probably want it to be within 1-30 range, because that's the max size of the array.
I think I fixed it so everything should be ok now. But thanks for the pointers.
Topic archived. No new replies allowed.