有没有办法将const双变成数组C++? 所以,我创建了一个简单的成绩平均计算程序,基本上是C++初学者的课程,这是我很新的。我的任务现在要求我合并一个数组。我很难确定是否可以将代码的某些方面(如常量双精度或双精度)更改为数组,或者是否需要重新开始我的程序 #include <iostream> using namespace std; int main(){ cout << "Welcome to the GPA Calculation Program!"; cout << "Lets get started."; const double A = 4.0 const double A_MINUS = 3.67 const double B_PLUS = 3.33 const double B = 3.0 const double B_MINUS = 2.67 const double C_PLUS = 2.33 const double C = 2.0 const double C_MINUS = 1.67 const double D = 1.0 const double F = 0.0 string studentName; string lettergrade; double credit; double calTimes = 0; double totalCal = 0; double totalCredit = 0; double finalGPA = 0; int option;

有没有办法将const双变成数组C++? 所以,我创建了一个简单的成绩平均计算程序,基本上是C++初学者的课程,这是我很新的。我的任务现在要求我合并一个数组。我很难确定是否可以将代码的某些方面(如常量双精度或双精度)更改为数组,或者是否需要重新开始我的程序 #include <iostream> using namespace std; int main(){ cout << "Welcome to the GPA Calculation Program!"; cout << "Lets get started."; const double A = 4.0 const double A_MINUS = 3.67 const double B_PLUS = 3.33 const double B = 3.0 const double B_MINUS = 2.67 const double C_PLUS = 2.33 const double C = 2.0 const double C_MINUS = 1.67 const double D = 1.0 const double F = 0.0 string studentName; string lettergrade; double credit; double calTimes = 0; double totalCal = 0; double totalCredit = 0; double finalGPA = 0; int option;,c++,arrays,constants,double,C++,Arrays,Constants,Double,你可以在C++中创建这样的数组: int arr[5]; // This creates an array of 5 ints int arr[5] = {6, 3, 2, 4, 2}; int arr[] = {6, 3, 2, 4, 2}; arr[0]; // Returns first element (6) 您甚至可以在初始化时赋值,如下所示: int arr[5]; // This creates an array of 5 ints int arr[5] = {6, 3,

你可以在C++中创建这样的数组:

int arr[5]; // This creates an array of 5 ints
int arr[5] = {6, 3, 2, 4, 2};
int arr[] = {6, 3, 2, 4, 2};
arr[0]; // Returns first element (6)
您甚至可以在初始化时赋值,如下所示:

int arr[5]; // This creates an array of 5 ints
int arr[5] = {6, 3, 2, 4, 2};
int arr[] = {6, 3, 2, 4, 2};
arr[0]; // Returns first element (6)
您还可以删除方括号之间的大小,让编译器为您推断数组的大小,如下所示:

int arr[5]; // This creates an array of 5 ints
int arr[5] = {6, 3, 2, 4, 2};
int arr[] = {6, 3, 2, 4, 2};
arr[0]; // Returns first element (6)
无论哪种方式,您都可以访问如下元素:

int arr[5]; // This creates an array of 5 ints
int arr[5] = {6, 3, 2, 4, 2};
int arr[] = {6, 3, 2, 4, 2};
arr[0]; // Returns first element (6)

请记住,在数组中,它不是从1..size索引的,而是从0..size-1索引的,因此如果数组长度为10个元素,则有效索引将为0..9。

不要链接到外部资源。请把密码贴在这里,放在适当的地方。请拿着密码仔细阅读。请在问题中插入代码,而不是提供链接。顺便问一下,平均绩点是多少?我从来没有听说过这个问题,或者在C++课程中没有意义。只是复制粘贴代码到问题中去。系统只会限制你发布太多的代码和太少的文本,它不应该要求你发布图像。如果你搞砸了,通常会有人很好地修复你的代码格式。或者查看我们的,并注意到您可以随时查看您的问题。因此,我尝试复制粘贴代码到问题中,但它也尝试添加图像,因此我不太确定我做错了什么。我编辑了我的原始帖子;GPA是平均成绩点。我应该把它全打出来。我道歉。这个程序是一个计算程序。所以如果我想给数组赋值,我能做什么?例如,为其值指定等级字母,但使用数组?这有意义吗?