I'm having problems getting the last part of this program to work. Help!!
Code:
//reverse array prblm 5 pg.290 c++ primer plus
#include <iostream>
using namespace std;
int fill_array(double ar[], int limit);
void show_array(const double ar[],int limit);
void reverse(double ar[],int limit);
int main()
{
int limit=20;
double ar[20];
limit=fill_array(ar,limit);
cout << "You entered:\n";
show_array(ar,limit);
reverse(ar,limit);
cout << "Reversed:\n";
show_array(ar,limit);
cout << "Reversed again except for first and last elements:\n";
reverse(ar+1,limit-1);
show_array(ar,limit);
return 0;
}
int fill_array(double ar[], int limit)
{
double temp;
int i;
for (i=0;i<limit; i++)
{
cout << "Enter value #"<<(i+1)<<":";
if (!(cin>>temp))
break;
ar[i]=temp;
}
return i;
}
void show_array(const double ar[],int limit)
{
for (int i=0;i<limit;i++)
{
cout << "Array element #" << (i+1) << ":" << ar[i] << endl;
}
}
void reverse(double ar[],int limit)
{
double temp;
for (int i=0;i<limit;i++)
{
if (i==limit-i-1)
break;
temp=ar[limit-i-1];
ar[limit-i-1]=ar[i];
ar[i]=temp;
}
}