trouble printing an array....

I'm having some trouble printing out an array forwards. I'm figuring out the high and low of an array and did soo, but can't print out. My result is zero. if anyone could help that would be great, and if anyone has any hints to printing an array backwards that would also be great. here is my code so far. 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
   #include <iostream>
using namespace std;

int main()
{
	
	const int max = 15;
	float number[max];
	float low = 0.00;
	float high = 0;
	int i;

	

	cout << "Please type 15 Stock Market values.\n";

	for( int i = 0; i < max; i++ )
	     {
		cout << "Value " << i + 1 << ":           ";
		cin >> number[i];
		
	     }
	for( int i = 0; i < max; i++ )
	  {
	if (number[i] > high)
			high = number[i];
			cout << "The Highest Value is:          " << high<< endl;
		if (number[i] < low)
			low = number [i];
			cout << "The lowest Value is:           " << low << endl;
			cout << endl;
	  }
	cout << number[max]<< endl;

// I Tried using this type of code like they show using gradebooks, but i am confused 
	// I dont think i am going in the right direction
	
	





	return 0;
} 
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
#include <iostream>
using namespace std;

int main()
{
	
	const int max = 25;
	float number[max];
	float low = 9999999999999.00;
	float high = 0;
	int i;

	

	cout << "Please type 15 Stock Market values.\n";

	for( int i = 0; i < max; i++ )
	{
		cout << "Value " << i + 1 << ":           ";
		cin >> number[i];
		
	}
	for( int i = 0; i < max; i++ )
	{
		if (number[i] > high) high = number[i];			
		if (number[i] < low) low = number [i];								
	}
	cout << number[max]<< endl;
	cout << "The Highest Value is:          " << high<< endl;
	cout << "The lowest Value is:           " << low << endl;
	
// I Tried using this type of code like they show using gradebooks, but i am confused 
	// I dont think i am going in the right direction


	return 0;
} 



" hints to printing an array backwards"

for (int i = max; i > =0; i--) cout << number[i];
Last edited on
Thanks ! i finally got it. i see i had to switch a couple of things around. And a question that relates to this ; are the "ptrs" used the same way as this array was worked out? Because i have to figure out the same exact thing, but using "ptrs" instead.
Do you mean "ptrs" as pointers?

Some tutorials about pointers and arrays:

"...Well, these bracket sign operators [] are also a dereference operator known as offset "operator. They dereference the variable they follow just as * does, but they also add the number between brackets to the address being dereferenced. For example:"


1
2
a[5] = 0;       // a [offset of 5] = 0
*(a+5) = 0;     // pointed by (a+5) = 0  



http://www.cplusplus.com/doc/tutorial/pointers/

http://www.uow.edu.au/~lukes/TEXTBOOK/notes-cpp/arrayptr/26arraysaspointers.html
Ok i see. I looked at the tutorial and it explained it to me better than what my teacher has taught me so far. It makes sense. Thanks, i appreciate it! I was struggling there for a moment.
Topic archived. No new replies allowed.