鱼C论坛

 找回密码
 立即注册
查看: 2991|回复: 3

c++一个问题!

[复制链接]
发表于 2013-12-6 23:23:46 | 显示全部楼层 |阅读模式
1鱼币
#include <iostream>
using namespace std;

struct xs
{
        int xh;
        char name[20];
        double cj[2];
}xs[100];

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[100].xh;
                cout << "输入学生姓名:";
                        cin >> xs[100].name[20];
                cout << "输入语文成绩:";
                        cin >> xs[100].cj[0];
                cout << "输入数学成绩:";
                        cin >> xs[100].cj[1];
                cout << "输入英语成绩:";
                        cin >> xs[100].cj[2];
                cout << "是否继续输入?(Y/N):";
                        int a;
                        cin >>a;
                        if (a=='n'||a=='N')
                                break;
        }
        system("cls");
}

这个代码按N或n退出以后会无限循环死循环while里的语句 这是为什么啊?

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-12-7 12:29:16 | 显示全部楼层
int a;??
是 char a;把
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-12-7 16:56:41 | 显示全部楼层
本帖最后由 仰望天上的光 于 2013-12-7 16:59 编辑
  1. #include <iostream>
  2. using namespace std;

  3. struct xs
  4. {
  5.          int xh;
  6.          char name[20];
  7.          double cj[2];
  8. }xs;

  9. void shuru(); int main()
  10. {
  11.          cout << "                      学生成绩管理系统v6.0版"<<endl;
  12.          cout << "==================================================================="<<endl;
  13.          cout << "                      1.输入学生成绩"<<endl;
  14.          cout << "                      2.输出学生成绩"<<endl;
  15.          cout << "                      3.学生成绩统计"<<endl;
  16.          cout << "                      4.学生成绩查询"<<endl;
  17.          cout << "                      请输入1~4 (按0退出)"<<endl;
  18.          int sh;
  19.          cin >> sh;
  20.          switch (sh)
  21.          {
  22.                  case 1:shuru();
  23.                          break;
  24.          }
  25.          system("pause");

  26. }
  27. void shuru()
  28. {
  29.          while(true)
  30.          {
  31.                  cout << "输入学生学号:";
  32.                          cin >> xs.xh;
  33.                  cout << "输入学生姓名:";
  34.                          cin >> xs.name;
  35.                  cout << "输入语文成绩:";
  36.                          cin >> xs.cj[0];
  37.                  cout << "输入数学成绩:";
  38.                          cin >> xs.cj[1];
  39.                  cout << "输入英语成绩:";
  40.                          cin >> xs.cj[2];
  41.                  cout << "是否继续输入?(Y/N):";
  42.                          char a;
  43.                          cin >>a;
  44.                          if (a=='n'||a=='N')
  45.                                  break;
  46.          }
  47.         system("cls");
  48. }

复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-12-7 20:55:06 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-12 04:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表