鱼C论坛

 找回密码
 立即注册
查看: 2763|回复: 5

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

[复制链接]
发表于 2014-9-23 21:58:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 剑雨君 于 2014-9-24 18:21 编辑
  1. //不知道为什么我输不出小数点出来,请各位大神看看!!
复制代码
  1. #include< iostream >
  2. #include <iomanip>
  3. using namespace std;

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

  14. int main()
  15. {
  16.         Stu Student[ 100 ];
  17.         int count;        //人数
  18.         int i;
  19. loop:
  20.         cout << "请输入要录入成绩的人数:";
  21.         cin >> count;
  22.         
  23.         if( count <= 0 )
  24.         {
  25.                 cout << "输入错误!";
  26.                         goto loop;
  27.         }

  28.         for( i = 0; i < count; i++ )
  29.         {
  30.                 cout << "学号:                        ";
  31.                 cin >> Student[ i ].num;
  32.                 cout << "姓名:                        ";
  33.                 cin >> Student[ i ].name;
  34.                 cout << "大学英语:                ";
  35.                 cin >> Student[ i ].ue;
  36.                 cout << "离散数学:                ";
  37.                 cin >> Student[ i ].dm;
  38.                 cout << "数据结构:                ";
  39.                 cin >> Student[ i ].ds;
  40.                 cout << "OOP:                        ";
  41.                 cin >> Student[ i ].oop;

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

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

  46.         i = 0;

  47.         float all_av = 0.0;

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

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

  55.         return 0;
  56. }
复制代码


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

使用道具 举报

 楼主| 发表于 2014-9-23 22:00:57 | 显示全部楼层
代码复制上来有点不整齐 不好意思啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-9-24 15:02:46 | 显示全部楼层
什么叫输出的小数点有问题。。。具体一点吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-9-24 18:21:16 | 显示全部楼层
elvo 发表于 2014-9-24 15:02
什么叫输出的小数点有问题。。。具体一点吧

我输不出来小数点,明明都用了控制输出小数点位数的语句
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2014-9-24 20:24:53 | 显示全部楼层
汇编跟踪下吧   对输入输出流不是很了解
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-9-24 22:06:32 | 显示全部楼层
hacker.jin 发表于 2014-9-24 20:24
汇编跟踪下吧   对输入输出流不是很了解

刚学汇编。。我试试。。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-4 23:43

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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