help with arrays

Oct 29, 2013 at 4:16pm
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
Oct 29, 2013 at 4:31pm
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 Oct 29, 2013 at 4:32pm
Oct 29, 2013 at 4:36pm
you only compute the sum of the numbers that are greater than or equal to 10 thanks
Oct 29, 2013 at 4:39pm
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 Oct 29, 2013 at 4:40pm
Oct 29, 2013 at 4:47pm
int k;
cin>>k; why did you declare another variable?

and in arrays how did the program know sum process?

thanks
Oct 29, 2013 at 5:29pm
up pls reply someone thanks
Oct 29, 2013 at 10:38pm
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 Oct 29, 2013 at 10:39pm
Topic archived. No new replies allowed.