How to input values after for loop in C++?
I have to make a program which inputs 10 student's grades and displays their weighed and unweighted averages. I am new to C++ programming so I don't know m开发者_如何学JAVAuch and my professor doesn't like it when people use things he hasn't taught.
Here's the code: It shows up as What are the four test scores of student 1,2, etc. How can I make it to be when it says "What are the four test scores of student 1", then I would be able to enter those in. And then on to student2, student3, etc?
Thank you for your time.
#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;
}
I think you want to read four values for each students, if so , then understand this code:
#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...
}
Now since it's your homework, do the rest of your work yourself. All the best!
精彩评论