数组函数 一例(数组填充)

#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;
}

posted @ 2007-02-04 03:23  Edward Xie  阅读(267)  评论(0)    收藏  举报