C++ 初学者关于 getline 的问题
大家好,我的问题是这个程序的第一个for loop里面只能输入第一次的信息,第一次循环后就会自动跳过接下来输入流程直接到最后结果,实在不知道该怎么办。求救呀!!!!#include <iostream>
using namespace std;
int main()
{
const int size1 = 5, size2 = 4;
char check;
string student[size1];
int grade[size1][size2];
for(int c=0; c<=4; c++)
{
cout<< "Student" << c+1 << " name: ";
getline(cin,student[c]);
cout << "Grade: ";
do
{
check = 'y';
for(int d=0; d<=3; d++)
{
cin >> grade[c][d];
if(grade[c][d]<0 || grade[c][d]>100)
check = 'n';
}
if(check == 'n')
{
cout << "Invalid grade. Enter again.\n";
cout << "Grade: ";
}
}while(check == 'n');
}
int sum;
double average;
char letter;
for (int c=0; c<=4; c++)
{
sum = 1;
for(int d=0; d<=3; d++)
sum += grade[c][d];
average = sum/4.00;
if(average>=90 && average <=100)
letter = 'A';
else if(average>=80 && average<90)
letter = 'B';
else if(average>=70 && average<80)
letter = 'C';
else if(average>=60 && average<70)
letter = 'D';
else if(average>=0 && average<60)
letter = 'F';
cout << "Student name: " << student[c]<<endl;
cout << "Average grade: " << average<<endl;
cout << "Letter grade: " << letter<<endl;
cout << "----------------------------";
cout << endl;
}
}