剑雨君 发表于 2014-9-23 21:58:22

C++输不出小数点,求解。

本帖最后由 剑雨君 于 2014-9-24 18:21 编辑

//不知道为什么我输不出小数点出来,请各位大神看看!!
#include< iostream >
#include <iomanip>
using namespace std;

typedef struct Student
{
      char num[ 13 ];                        //学号
      char name[ 9 ];                        //姓名
      unsigned short int ue;      //大学英语
      unsigned short int dm;      //离散数学
      unsigned short int ds;      //数据结构
      unsigned short int oop;      //OOP
      float av;                              //平均成绩
}Stu;

int main()
{
      Stu Student[ 100 ];
      int count;      //人数
      int i;
loop:
      cout << "请输入要录入成绩的人数:";
      cin >> count;
      
      if( count <= 0 )
      {
                cout << "输入错误!";
                        goto loop;
      }

      for( i = 0; i < count; i++ )
      {
                cout << "学号:                        ";
                cin >> Student[ i ].num;
                cout << "姓名:                        ";
                cin >> Student[ i ].name;
                cout << "大学英语:                ";
                cin >> Student[ i ].ue;
                cout << "离散数学:                ";
                cin >> Student[ i ].dm;
                cout << "数据结构:                ";
                cin >> Student[ i ].ds;
                cout << "OOP:                        ";
                cin >> Student[ i ].oop;

                Student[ i ].av = ( float )( ( Student[ i ].ue + Student[ i ].dm + Student[ i ].ds + Student[ i ].oop ) / 4 );

                cout << "平均成绩:                ";
                cout <<setprecision(4) << Student[ i ].av << endl;
      }

      i = 0;

      float all_av = 0.0;

      while( i < count )//计算全体学生的平均成绩
      {
                all_av += Student[ i ].av;
                i++;
      }

      cout << "全体学生的平均成绩:";
      cout << setprecision(4) << ( float )( ( all_av ) / i ) << endl;

      return 0;
}

剑雨君 发表于 2014-9-23 22:00:57

代码复制上来有点不整齐 不好意思啊

elvo 发表于 2014-9-24 15:02:46

什么叫输出的小数点有问题。。。具体一点吧

剑雨君 发表于 2014-9-24 18:21:16

elvo 发表于 2014-9-24 15:02
什么叫输出的小数点有问题。。。具体一点吧

我输不出来小数点,明明都用了控制输出小数点位数的语句

hacker.jin 发表于 2014-9-24 20:24:53

汇编跟踪下吧   对输入输出流不是很了解

剑雨君 发表于 2014-9-24 22:06:32

hacker.jin 发表于 2014-9-24 20:24
汇编跟踪下吧   对输入输出流不是很了解

刚学汇编。。我试试。。
页: [1]
查看完整版本: C++输不出小数点,求解。