Printing out specific values in arrays

Are there any online resources that give you real world references and example code? My problem is that my homework on arrays involves looking through an array and listing only certain values. Our lessons have only done simple equations like making 3 dimensional arrays to find the sum[i] of num1[i] and num2[i]. Really simple stuff.

Here's my problem. I need to print a list of Ids of sales over 5000, then the number of records with sales less than 500. I was able to figure out the latter with a simple count, but the former.. I can only print out one entry and it is often incorrect. I learn by examples so I'm not sure where I'm going wrong with what we've gone over already. Here is my program:

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
#include <iostream.h>

int main()
{


int names[5], sales[5], greater[5];
int i;

for (i=0; i<5; i++)
	{
	cout<<"enter id and sale amount: ";
	cin>>names[i]>>sales[i];
	}

int count =0;

for (i=0;i<5;i++)
	{
	if (sales[i]> 5000)

    names[i] = greater[i];

	if (sales[i] < 500)

			count++;

	}



cout<<"\nID of sales greater than 5000: "<<endl;
cout<<greater[i];

cout<<"\nNumber of sales less than 500: "<<count;
  
return 0;

}

Hi,

There is reference material, articles and tutorials at the top left of this page.

The greater array is not initialised, but you assign values from it, overwriting what's in the names array.

I can only print out one entry and it is often incorrect.


Line 33 only prints 1 value.
Thank you!
Topic archived. No new replies allowed.