如何在c++中for循环后输入值
How to input values after for loop in C++?
我必须编写一个程序,输入10个学生的成绩,并显示他们的加权和未加权平均数。我是c++编程的新手,所以我知道的不多,而且我的教授不喜欢人们使用他没有教过的东西。
下面是代码:它显示为学生1、2等的四个测试分数是多少。我怎么才能让它变成"学生1的四项考试成绩是多少",然后我就可以输入这些了。然后是学生2,学生3,等等?
感谢您的宝贵时间。
#include <iostream>
using namespace std;
const int numberofstudents = 10;
int main()
{
int student;
for(student=1; student<=numberofstudents; student++)
cout << "nWhat are the four test scores of student number " << student << endl;
return 0;
}
我认为你想为每个学生读四个值,如果是这样,那么理解这段代码:
#include <iostream>
using namespace std;
int main()
{
const int numberofstudents = 10;
double scores[numberofstudents][4];
for(int student=0; student<numberofstudents; student++)
{
cout << "nWhat are the four test scores of student number " << (student+1) << endl;
int i = 0;
while ( i < 4 )
{
//scores is a two dimentional array
//scores first index is student number (starting with 0)
//and second index is ith score
cin >> scores[student][i]; //read score, one at a time!
i++;
}
}
//process scores...
}
既然这是你的家庭作业,剩下的就自己做吧。祝一切顺利!
相关文章:
- 正在尝试了解输入验证循环
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 通过for循环使用用户输入填充列表
- 计算用户使用循环输入的整数数量
- 从文件循环输入的更合适方法?
- 实现递归函数,避免由 C++ 中 include 的循环调用(没有 #pragma 一次)引起的无限循环输入
- 我应该使用 DeviceContext 函数在管道中循环输入还是通过创建来输入
- 如何在代码中插入循环输入
- 循环输入数据
- 为循环输入并中断C++:至少10次迭代且没有空字符串
- 第一次通过循环输入空字符串?(c++)
- 使用while循环输入的小问题
- 下次不会让我通过 while (true) 循环输入信息
- 我如何让一个数组来存储用户在 C 中使用 do-while 循环输入的最多 10 个元素
- C++循环 - 输入整数,直到用户退出
- 将随机数插入到数组中,其中每个值都是通过 for 循环输入的
- 从文件循环输入流
- 这个函数请求用户通过循环输入文件名的错误在哪里?
- cin.当循环输入时失败
- 如何添加循环输入文件的结果