copying an array to an array

Need to copy the miles array to distance array. And display the distance array. Im getting distance = 0. Any suggestiong to modify the code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;
int main()
{
  const int VALUES = 7;
  int miles[VALUES] = {15, 22, 16, 18, 27, 23, 20};
  int distance[VALUES];
  int *m, *d;

  m = miles;
  d = distance;
  for(int *m = miles, *d = distance; m != miles + VALUES; m++, d++)
    *m = *d;

  cout << "The distance is " << *m++ << endl;
  return 0;
}
*m = *d; should be *d = *m;

cout << "The distance is " << *m++ << endl;
You can't display an array like that. You must loop through array and display each element separately.
1
2
3
4
5
  cout << "The distance is ";
  for(int *m = miles; m != miles + VALUES; m++)
    {
       cout << *m<<' ';
    }

Topic archived. No new replies allowed.