代码通过编译,但是运行不了,
#include <iostream>const int Max = 5;
double * fill_array( double * begin, double * end);
void show_array(const double * begin, const double * end);
void revalue(double r, double * begin, double * end);
using namespace std;
int main()
{
double str[Max];
double * strp = fill_array(str, str+Max);
show_array(str, strp+1);
if (*strp > 0)
{
cout << "Enter revaluation factor: ";
double factor;
while (!(cin >> factor))
{
cin.clear();
while (cin.get() != '\n')
continue;
cout << "Bad input; Please enter a number: ";
}
revalue(factor, str, strp+1);
show_array(str, strp+1);
}
cout << "Done!\n";
return 0;
}
double * fill_array( double * begin, double * end)
{
double * pb;int i;
for (pb = begin,i = 0; pb != end; pb++,i++)
{
int temp;
cout << "Enter value # " << i+1 << ": ";
cin >> temp;
if (!cin)
{
cin.clear();
while (cin.get() != '\n')
continue;
break;
}
else if (temp < 0)
break;
*pb = temp;
}
return pb;
}
void show_array(const double * begin, const double * end)
{
const double * pb;
for (pb = begin; begin != end; pb++)
{
cout << *pb << endl;
}
}
void revalue(double r, double * begin, double * end)
{
double * pb;
for (pb = begin; pb != end; pb++)
*pb = *pb * r;
}
大神帮忙看看!