有两行代码我不明白
该程序是计算全班平均分,且全班人数未知。但不知为何一旦将while上的两行去掉(有箭头指的)程序便不能给出正确答案,还望各位高手指教。
{
int total, //sum of grades
grade, // score
gradecounter; //num of grades entered
total = 0,grade = 0,gradecounter = 0;
》cout << "please enter grade,-1 to end \n";
》 cin >> grade;
while ( grade != -1 ) { // "-1" indicate end
total = total + grade;
gradecounter++;
cout << "please enter grade,-1 to end \n";
cin >> grade;
}
』