c++一个问题!
#include <iostream>using namespace std;
struct xs
{
int xh;
char name;
double cj;
}xs;
void shuru();
int main()
{
cout << " 学生成绩管理系统v6.0版"<<endl;
cout << "==================================================================="<<endl;
cout << " 1.输入学生成绩"<<endl;
cout << " 2.输出学生成绩"<<endl;
cout << " 3.学生成绩统计"<<endl;
cout << " 4.学生成绩查询"<<endl;
cout << " 请输入1~4 (按0退出)"<<endl;
int sh;
cin >> sh;
switch (sh)
{
case 1:shuru();
break;
}
system("pause");
}
void shuru()
{
while(true)
{
cout << "输入学生学号:";
cin >> xs.xh;
cout << "输入学生姓名:";
cin >> xs.name;
cout << "输入语文成绩:";
cin >> xs.cj;
cout << "输入数学成绩:";
cin >> xs.cj;
cout << "输入英语成绩:";
cin >> xs.cj;
cout << "是否继续输入?(Y/N):";
int a;
cin >>a;
if (a=='n'||a=='N')
break;
}
system("cls");
}
这个代码按N或n退出以后会无限循环死循环while里的语句 这是为什么啊?
int a;??
是 char a;把 本帖最后由 仰望天上的光 于 2013-12-7 16:59 编辑
#include <iostream>
using namespace std;
struct xs
{
int xh;
char name;
double cj;
}xs;
void shuru(); int main()
{
cout << " 学生成绩管理系统v6.0版"<<endl;
cout << "==================================================================="<<endl;
cout << " 1.输入学生成绩"<<endl;
cout << " 2.输出学生成绩"<<endl;
cout << " 3.学生成绩统计"<<endl;
cout << " 4.学生成绩查询"<<endl;
cout << " 请输入1~4 (按0退出)"<<endl;
int sh;
cin >> sh;
switch (sh)
{
case 1:shuru();
break;
}
system("pause");
}
void shuru()
{
while(true)
{
cout << "输入学生学号:";
cin >> xs.xh;
cout << "输入学生姓名:";
cin >> xs.name;
cout << "输入语文成绩:";
cin >> xs.cj;
cout << "输入数学成绩:";
cin >> xs.cj;
cout << "输入英语成绩:";
cin >> xs.cj;
cout << "是否继续输入?(Y/N):";
char a;
cin >>a;
if (a=='n'||a=='N')
break;
}
system("cls");
}
仰望天上的光 发表于 2013-12-7 16:56 static/image/common/back.gif
我知道了 但是要怎么输出这个呢?做到按学号按名字查询的效果?
页:
[1]