Pointers/array/function problem

a) Write a program has a declaration in main() to store the following numbers
into an array named rates: 6.5, 7.2,7.5, 8.7, 8.6,9.4,9.6,9.8,10.0. there should
be a function call to show() that accepts rates in a parameter argument named
rates and then displays the numbers using the pointer notation *(rates+i);
b) Modify the show() function written above to alter the address in rates.
Always use the expression *rates rather than *(rates+i) to retrieve the
correct element.


My code is pretty sporadic and sloppy because I was just throwing things in trying to piece together a code. Obviously the code was unsuccessful so I would just like some guidance because pointers are still pretty foreign to me.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 #include <iostream>
using namespace std;
const int num= 9;
double show( double rates[num]);
int main()
{
	double rates[num]= {6.5, 7.2,7.5, 8.7, 8.6,9.4,9.6,9.8,10.0};
	
	
	double show(rates[num]);

}

double  show( double rates[num])
{
	double *y;
	for (int i=0; i<num; i++)
		{ 
		y= *(rates+i);
		cout<< "Array location "<<i<<" is: "<< *y<< endl;
	}
	system("pause");
	return 0;
}
Line 10 should be:
 
	show(rates);


Line 19 should be:
 
y = (rates+i);

Topic archived. No new replies allowed.