#include<iostream>
using namespace std;
int main()
{
char k='f';
int i=0,j=0,s=0;
while(k!='n')
{
double a[5],b[1];
cout<<"请输入学生的学号:";
cin>>b[j];
cout<<endl;
j++;
cout<<"请输入"<<a[j]<<"学生的高数成绩:";
cin>>a[i];
cout<<endl;
s=s+a[i];
i++;
cout<<"请输入"<<a[j]<<"学生的英语成绩:";
cin>>a[i];
cout<<endl;
s=s+a[i];
i++;
cout<<"请输入"<<a[j]<<"学生的c++成绩:";
cin>>a[i];
cout<<endl;
s=s+a[i];
i++;
a[i]=s/3;
i++;
cout<<"如果要结束请按n,按其它键继续:";
cin>>k;
}
while(j>0)
{
while(i>=0)
{
cout<<a[i]; //error C2065: 'a' : undeclared identifier//error C2109: subscript requires array or pointer type
i=i-1;
}
cout<<endl;
j=j-1;
}
return 0;
}
几位高手说的都很对!那个错误我已改正,但问题还没解决!请各位高手在帮忙看一下,不胜感激!首先,我要表达的效果(则在显示器显示的)是:
请输入学生的学号:1
请输入1学生的高数成绩:80
请输入1学生的英语成绩:90
请输入1学生的C++成绩:100
如果要结束请按n,按其它键继续:f
请输入学生的学号:2
请输入2生的高数成绩:80
请输入2生的英语成绩:80
请输入2学生的C++成绩:80
如果要结束请按n,按其它键继续:n
学号 高数 英语 C++ 平均分
1 80 90 100 90
2 80 80 80 80
谢谢cout<<"请输入"<<b[j]<<"学生的高数成绩:";才是对的!
循环体之前声明数组a也是对的,不过出了另外一个问题:循环过后,定义的数组就不够了。