在 for 循环和变量值中获取此代码的多个错误;

getting multiple errors for this code within the for loop and for the variable value;

本文关键字:代码 错误 获取 循环 for 变量值      更新时间:2023-10-16

使用变量值作为数组的大小,但它不会让我这样做。

int main () {
    double a,b,N,increment,value;
    value=0;
    cout<< "enter values for (a,b,N)";
    cin>>a;
    cin>>b;
    cin>>N;
    increment= (b-a)/(N-1);
    for (int i =0;i<=b;i+=increment){
    value = value+i;    
    }
    double sivalues[value];
    for (int x=a;i<=b;i+=increment){
        sivalues[a]=si(x);
        cout<<"si("<<x<<") = "<< sivalues[a];
    }

创建数组时放置在 [] 内的项必须是常量。 但是,当您在堆上创建数组时,这不适用。

int mySize = 50;
int myArray[mySize]; // error: mySize must be const
int* myHeapArray = new int[mySize]; // all good! (just don't forget to free the memory)