【发布时间】:2015-09-19 20:52:20
【问题描述】:
我了解数组的工作原理,尽管它们的尺寸很大,但如果没有这些基本信息,我无法将它组合到代码中。如您所知,我从第 13 行开始尝试了多种方法,但都失败了。
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main()
{
int MasterArray [3][3][2]; // Declaration of the Array
int one = 0, two = 0, three = 0; // Declaration of Variables
cout << "Would you like to edit class 1 or 2?" << endl ; //Ask for input
cin >> one; // store input in the variable named one
one -=1; // Since c++ is 0 based input - 1 = one
MasterArray[3][3][2] = {{one, two, three}, {one, two, three}, {one, two}};
// Above line attempt to store variable one in array
// Rinse and repeat this process for lower lines, but storing is all that matters.
cout << "Which student account would you like to access 1, 2, or 3?";
cin >> two;
two -= 1;
MasterArray[3][3][2] = [one][two][three];
cout << "Which grade would you like to edit 1, 2, or 3?";
cin >> three;
three -= 1;
MasterArray[3][3][2] = [one][two][three];
cout << MasterArray[one][two][three];
return 0;
}
【问题讨论】:
-
不清楚您要做什么,也不清楚您为什么要使用 3D 而不是 2D。
-
为什么要使用 3D 数组,尤其是当您刚刚学习 C++ 时。您可能想查看
struct来保存数据而不是用于存储的多维数组。 -
我是新手,所以不让上传图片,但是我的老师要求在这个作业中使用 3x3x2 数组。
-
postimg.org/image/sqj2qr6hp ------------------------- postimg.org/image/nwa8mkv2n 而且我们还没有学过结构。
-
您的讲师是否覆盖了
new和delete?
标签: c++ arrays multidimensional-array user-input storing-data