免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1171 | 回复: 1
打印 上一主题 下一主题

[C++] 请教一个程序在vc++里面编译不能通过的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-04-16 22:59 |只看该作者 |倒序浏览
为什么我的这段代码在vc++里 编译会有这种错误呢?是什么原因呢?

代码如下
#include "stdio.h"
void cour_ave (int a, int b,float score[])
{
        int course ,stud;
        float total1,aver1;
        for (course = 0; course < b; course++)
        {
                total1 = 0 ;
                for ( stud = 0;stud < a;stud++)
                        total1 = total1 + score[stud*b+course];
                aver1 = total1 / a;
                printf ("average of course %d is :%6.2f\n",course,aver1);
        }
        return;
}


void stud_ave (int a, int b,float score[])
{
        int course ,stud;
        float total2,aver2;
        printf("\n";
        for (stud = 0;stud < a ;stud++)
        {
                total2 = 0;
                for (course = 0;course < b;course ++)
                        total2 = total2 + score[stud * b + course ];
                aver2 = total2 / b;
                printf ("average of student %d is %6.2f\n",stud,aver2);
        }
        return;
}


#define a 4
#define b 3
void main ()
{
        void cour_ave (int x,int y,float score[]);
        void stud_ave(int x,int y,float score[]);
        float score[a]={{89,78,56},{88,99,100},{72,80,61},{60,70,75}};
        cour_ave(a,b,score);
        stud_ave(a,b,score);
        return;
}


编译提示信息如下:

ompiling...
stand.cpp
D:\Program Files\Microsoft Visual Studio\MyProjects\zhou\stand.cpp(42) : error C2664: 'cour_ave' : cannot convert parameter 3 from 'float [4][3]' to 'float []'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\Program Files\Microsoft Visual Studio\MyProjects\zhou\stand.cpp(43) : error C2664: 'stud_ave' : cannot convert parameter 3 from 'float [4][3]' to 'float []'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

stand.obj - 2 error(s), 0 warning(s)

请帮我想想

论坛徽章:
0
2 [报告]
发表于 2004-04-16 23:18 |只看该作者

请教一个程序在vc++里面编译不能通过的问题

cour_ave(a,b,score[0]);
stud_ave(a,b,score[0]);

或者

cour_ave(a,b,&score[0][0]);
stud_ave(a,b,&score[0][0]);
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP