How do I find the highest number and the lowest number in pointers and arrays?

My assignment is to use pointers to point at the highest and lowest temperatures in the array.
I need to have 3 pointer variables and start them at the beginning of the array.
Step the pCur through the array using a for loop and pCur++.
Loop through the array looking for the high and low temperatures.
Make an if statement for pLow and PHigh if their values are found then print them out.

The problem I am having here is using pCur to step through the array.
pCur++;

I have no idea what that will do and how it will help find a highest and lowest temperature.

and for the if statements for pLow and pHigh
I need to make them like this
1
2
3
4
if ( *pCur < *pLow)
{
pLow = pCur; // have pLow point at the new low temprature
}


Here is my current code below
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

#include <iostream> 
using namespace std;

int main(){
	float *pCur;
	float *pHigh;
	float *pLow;
	const int MAXTEMPS = 10;
	float temps[MAXTEMPS];
	int t;
	pCur = temps;
	pHigh = temps;
	pLow = temps;


	for (t= 0; t < MAXTEMPS; t++)
	{
	cout << "Enter a temp: ";
	cin >> temps[t];
	}

	for (t= 0; t < MAXTEMPS; t++)
	{
	cout << temps[t] << endl;
	}



		system("Pause");
		return 0;
}
Google "pointer arithmetic".
you do not need the pointer of pCur.the array subscript can repalce the function. you can add
this code:
1
2
3
4
5
6
7
8
9
for(t=1;t<MAXTEMPS;t++)
	{
		if(*pLow>temps[t])
			pLow=&temps[t];
		if(*pHigh<temps[t])
			pHigh=&temps[t];
	}
cout<<*pLow<<endl;
cout<<*pHigh<<endl;
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
#include <iostream>
using namespace std;
#define MAXTEMPS  4

int _tmain(int argc, _TCHAR* argv[])
{
	
	float *pHigh = new float;
	float *pLow = new float;	
	float temps[MAXTEMPS];
	
	
	for (int t= 0; t < MAXTEMPS; t++)
	{
		cout << "Enter a temp: ";
		cin >> temps[t];
	}
		*pHigh  = temps[0];
		*pLow = temps[0];
	for (int t= 0; t < MAXTEMPS; t++)
	{
		
		if( *pLow > temps[t])
			*pLow = temps[t];

		
		if( *pHigh < temps[t])
			*pHigh = temps[t];
		
	}

	cout<<"\n High = "<< *pHigh;
	cout<<"\n Low = "<< *pLow;
	delete pHigh;
	delete pLow;

		system("Pause");

}
Topic archived. No new replies allowed.