注释处用指针又改怎么改才能运行啊? 我2个运行都报错
#include
#include
using namespace std;
int main()
{
double Da[100] ;
double Cl[100];
//double *Da = new double[1000];
//double *Cl = new double[1000];
Da[0] = Da[1] = 100.0;
Cl[0] = Cl[1] = 100.0;
int i=2;
do //(i = 2; Da[i] > Cl[i]; i++)
{
Da[i] = Da[1]+(i-1)*10.0;
Cl[i] = Cl[i - 1] * 1.05;
} while (Da[i++] > Cl[i++]);
cout << "How many years the property of Cl is more?: ";
cout << i << endl;
cout << "The property of Da: " << Da[i] << endl;
cout << "The property of Cl: " << Cl[i] << endl;
//delete[]Da;
//delete[]Cl;
getchar();
}
while 里面错了 i++了两次 判断的时候第二个 CI[i++]的时候 i 等于 3了 而CI[3] 没有值所以不能比较的 把你那个循环改了重写把
#include
#include
using namespace std;
int main()
{
double *Da = new double[1000];
double *Cl = new double[1000];
Da[0] = Da[1] = 100.0;
Cl[0] = Cl[1] = 100.0;
int i=2;
for(i = 2; Da[i] > Cl[i]; i++)
{
Da[i] = Da[1]+(i-1)*10.0;
Cl[i] = Cl[i - 1] * 1.05;
}
cout << "How many years the property of Cl is more?: ";
cout << i << endl;
cout << "The property of Da: " << Da[i] << endl;
cout << "The property of Cl: " << Cl[i] << endl;
delete[]Da;
delete[]Cl;
getchar();
}
我C++新手你看一下对不对?
考虑一下,是不是数组越界的问题~
你那个for循环的条件里面需要再加一个条件,保证数组不会越界!