This is a learning exercise-it is not course homework- so not urgent
When i try to compile it i get error messages about the insert() function as
commented below. Could someone explain what is wrong? If so thanks.
Here is test driver and offending function text code:
[CODE=cpp]#include<iostre am>
using namespace std;
void print(float x[],int n);
void insert(float x[],int n,float t);//doesn`t work
int main()
{
cout<<"\nInsert s a value into a sorted array\n";
float x[8]={22.3,33.4,44. 5,66.7,77.8};
cout<<"Array x [] is: ";
print(x,5);
insert(x,4,55.6 );
cout<<"\n\n";
system("pause") ;
return 0;
}
void print(float x[],int n)
{
for(int i=0;i<n;i++)
cout<<x[i]<<" ";
}
void insert(float x[],int n,float t)//this is not my work now; it is the published solution.
{
for(int i = n;i>0 && x[i-1]> t;i--)//using obsolete binding at 'i'
x[i]=x[i-1];
x[i]= t;//name lookup of i changed for new ISO 'for' scoping
}[/CODE]
When i try to compile it i get error messages about the insert() function as
commented below. Could someone explain what is wrong? If so thanks.
Here is test driver and offending function text code:
[CODE=cpp]#include<iostre am>
using namespace std;
void print(float x[],int n);
void insert(float x[],int n,float t);//doesn`t work
int main()
{
cout<<"\nInsert s a value into a sorted array\n";
float x[8]={22.3,33.4,44. 5,66.7,77.8};
cout<<"Array x [] is: ";
print(x,5);
insert(x,4,55.6 );
cout<<"\n\n";
system("pause") ;
return 0;
}
void print(float x[],int n)
{
for(int i=0;i<n;i++)
cout<<x[i]<<" ";
}
void insert(float x[],int n,float t)//this is not my work now; it is the published solution.
{
for(int i = n;i>0 && x[i-1]> t;i--)//using obsolete binding at 'i'
x[i]=x[i-1];
x[i]= t;//name lookup of i changed for new ISO 'for' scoping
}[/CODE]
Comment