C++ Break语句不在循环或开关语句中?
我的代码有问题,我读过这个网站的其他论坛关于这个问题,但它们与我的情况并不相关。我是新来的C++,我几乎没有3周的课程。我不知道为什么我的break语句不起作用,对我来说它在循环中。我错过了什么C++ Break语句不在循环或开关语句中?,c++,break,C++,Break,我的代码有问题,我读过这个网站的其他论坛关于这个问题,但它们与我的情况并不相关。我是新来的C++,我几乎没有3周的课程。我不知道为什么我的break语句不起作用,对我来说它在循环中。我错过了什么 float a[60][7]; int row; cout << "How many students would you like to grade?" << endl; cin >> studentNum; cout << "Enter grade
float a[60][7];
int row;
cout << "How many students would you like to grade?" << endl;
cin >> studentNum;
cout << "Enter grades for the first student" << endl;
row = 0;
n = studentNum - 2;
while (row < studentNum)
{
a[row][0]=k;
a[row][0] = row;
cout << "Enter grade for test 1: ";
cin >> a[row][1];
cout << "Enter grade for test 2: ";
cin >> a[row][2];
cout << "Enter grade for test 3: ";
cin >> a[row][3];
cout << "Enter grade for test 4: ";
cin >> a[row][4];
a[row][5] = (a[row][1] + a[row][2] + a[row][3] + a[row][4]) / 4;
a[row][6] = a[row][1] * 0.2 + a[row][2] * 0.3 + a[row][3] * 0.3 + a[row][4] * 0.2;
row++;
}
if (row == n)
{
cout << "Enter Grades for the last Student" << endl;
cout << "Enter grade for test 1: ";
cin >> a[row][1];
cout << "Enter grade for test 2: ";
cin >> a[row][2];
cout << "Enter grade for test 3: ";
cin >> a[row][3];
cout << "Enter grade for test 4: ";
cin >> a[row][4];
break;
}
else
{
cout << "Enter grades for the next student" << endl;
row = row + 1;
}
cout << "Stdnt" << "\t" << "Grade1" << "\t" << "Grade2" << "\t" << "Grade3" << "\t" << "Grade4" << "\t" << "Avg1" << "\t" << "Avg2" << endl;
printarray(a, studentNum);
cin.get();
return 0;
float a[60][7];
int行;
学生人数;
cout a[行][2];
cout>a[行][3];
cout>a[行][4];
[行][5]=(a[行][1]+a[行][2]+a[行][3]+a[行][4])/4;
[行][6]=a[行][1]*0.2+a[行][2]*0.3+a[行][3]*0.3+a[行][4]*0.2;
行++;
}
如果(行==n)
{
cout a[行][2];
cout>a[行][3];
cout>a[行][4];
打破
}
其他的
{
难道不能这样吗
float a[60][7];
int row = 0;
std::cout << "How many students would you like to grade?" << std::endl;
std::cin >> studentNum;
n = studentNum - 2;
std::cout << "Enter grades for the first student" << std::endl;
while (row <= n)
{
a[row][0] = k;
a[row][0] = row;
std::cout << "Enter grade for test 1: ";
std::cin >> a[row][1];
std::cout << "Enter grade for test 2: ";
std::cin >> a[row][2];
std::cout << "Enter grade for test 3: ";
std::cin >> a[row][3];
std::cout << "Enter grade for test 4: ";
std::cin >> a[row][4];
a[row][5] = (a[row][1] + a[row][2] + a[row][3] + a[row][4]) / 4;
a[row][6] = a[row][1] * 0.2 + a[row][2] * 0.3 + a[row][3] * 0.3 + a[row][4] * 0.2;
if (row==n)
{
std::cout << "Enter Grades for the last Student" << std::endl;
std::cout << "Enter grade for test 1: ";
std::cin >> a[row][1];
std::cout << "Enter grade for test 2: ";
std::cin >> a[row][2];
std::cout << "Enter grade for test 3: ";
std::cin >> a[row][3];
std::cout << "Enter grade for test 4: ";
std::cin >> a[row][4];
}
else
{
std::cout << "Enter grades for the next student" << std::endl;
}
row++;
}
std::cout << "Student" << "\t" << "Grade1" << "\t" << "Grade2" << "\t" << "Grade3" << "\t" << "Grade4" << "\t" << "Avg1" << "\t" << "Avg2" << std::endl;
printarray(a, studentNum);
std::cin.get();
return 0;
float a[60][7];
int行=0;
std::cout studentNum;
n=studentNum-2;
标准::cout a[行][3];
标准::cout>a[行][4];
[行][5]=(a[行][1]+a[行][2]+a[行][3]+a[行][4])/4;
[行][6]=a[行][1]*0.2+a[行][2]*0.3+a[行][3]*0.3+a[行][4]*0.2;
如果(行==n)
{
标准::cout a[行][2];
标准::cout>a[行][3];
标准::cout>a[行][4];
}
其他的
{
std::cout你想通过结尾的中断实现什么?如果真的很感谢你的帮助,我正在网上学习这门课程以获得成功,但我知道这是一个错误,我的教授不会回复我的电子邮件:(@Michael我想要“为最后一个学生输入分数”的声明)以最后一个学生结束评分。但是现在,当我运行程序时,“为最后一个学生输入分数”甚至不会弹出“为最后一个学生输入分数”出现在程序的最底部,您可能需要在while
循环中移动if
和else
,设置while(行是!非常感谢:)@MichaelRemove else子句中的额外行+。