c++ - 智能感知 : an array may not have elements of this type

标签 c++ c arrays multidimensional-array

我正在尝试构建一个二维数组,然后当我找到我需要的收入时,我会搜索合适的利率。

为了测试我的阵列并确保一切正常,我需要它来打印。问题是它一直说数组可能没有这种类型的元素......

数组不能有这种类型的元素。为什么不允许我在下标中输入所有这些费率。

int main(void)
{ 
    float income[] = {6000.00, 9000.00, 15000.00, 21000.00, 25000.00, 30000.00};
    float rates[][] = { { 2.8, 7.5, 9.6, 13.5, 15.5, 17.4 }, { 2.8, 7.5, 9.6, 13.5, 15.5, 17.4 } };

    for (int i = 0; i < 5; i++)
    {
        printf(" \n %i# income array:  %.2f \n", i, income[i]);

        printf("\n  %f ", rates[1][i]);
    }

    system("pause");

}

最佳答案

对于二维数组,您必须提供内部维度:

float rates[][6] = { { 2.8, 7.5, 9.6, 13.5, 15.5, 17.4 }, { 2.8, 7.5, 9.6, 13.5, 15.5, 17.4 } };

关于c++ - 智能感知 : an array may not have elements of this type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21980217/

相关文章:

c++ - 应用程序无法正确启动 (0xc000007b) Visual Studio C++

c++ - 在不设置环境变量的情况下在 Windows 7 中运行 MinGW gcc 编译器

c - 如何修改文件中的内容?

c - 如何将数组调用到另一个具有返回值的函数中?

arrays - 查找需要从数组中删除的元素,使得 2*min>max

c++ - C++函数可以返回具有构造函数和析构函数的对象吗

c++ - 如何在堆栈上分配指向指针的指针以及如何在堆上分配指针?

c++ - glColor不会改变opengl中其他三角形的颜色

c - 在 C 中获取当前语言环境的字符集?

c++ - 什么是堆栈?数组堆栈?数组队列?堆栈队列?它们在 C++ 中有何不同?