数组函数 一例(数组填充)
#include <iostream>
const int aa=8;
int fill_array(double ar[],int limit);
int main()
{
using namespace std;
double arrr[aa];
int kk=fill_array(arrr,aa);
cout<<kk<<endl;
return 0;
}
///////////////////////////////////////////////数组填充函数///////////////////////////////////////////////////////
int fill_array(double ar[],int limit) //int fill_array(double *ar,int limit)
{
using namespace std;
double temp;
int i;
for(i=0;i<limit;i++)
{
cout<<"enter value #"<<(i+1)<<": ";
cin>>temp; /-
///////////////////////////////////// chek the cin stream/////////////////////////// if(!cin>>temp);
if(!cin.good()) \-
{
cin.clear();
while(cin.get()!='\n')
{
continue;
}
cout<<"bad input.you must in put again.\n";
i-=1;
continue;
}
else if(temp<0)
break;
ar[i]=temp;
}
return i;
}


浙公网安备 33010602011771号