help with arrays

create a program that asks the user to input 10 integers of an array the program will add the numbers greater or equal to 10 need help guys thanks
Do you mean something like this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

int main()
{
	int array[10];
	int sum = 0;
	for ( int i = 0 ; i <= 10 ; ++i )
	{
		cout<<"Enter the value of the array with index "<<i<<" : ";
		cin>>array[i];
		sum += array[i];
	}

	cout<<"\nThe sum of array elements is: \n";
	cout<<sum<<endl;

	int k;
	cin>>k;
	return 0;
}
Last edited on
you only compute the sum of the numbers that are greater than or equal to 10 thanks
1
2
3
4
5
6
7
8
9
for ( int i = 0 ; i <= 10 ; ++i )
	{
		cout<<"Enter the value of the array with index "<<i<<" : ";
		cin>>array[i];
		if ( array[i] >= 10 )
		{
			sum += array[i];
		}
	}


;)
Last edited on
int k;
cin>>k; why did you declare another variable?

and in arrays how did the program know sum process?

thanks
up pls reply someone thanks
int k;
cin>>k; why did you declare another variable?

That bit is forcing the user to enter something before the program exits. It's a way of pausing the program.

Presumably, the way Uk Marine runs code, it runs in an IDE that displays a temporary console window and then destroys the window once the program exits, so this is a way of pausing it before it exits.

and in arrays how did the program know sum process?

I'm not sure I understand your question. The sum is repeatedly updated for each value of i here:
1
2
3
4
		if ( array[i] >= 10 )
		{
			sum += array[i];
		}
Last edited on
Topic archived. No new replies allowed.