| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 683 人关注过本帖
标题:小程序,哪里错了?
只看楼主 加入收藏
ddc
Rank: 2
等 级:新手上路
威 望:3
帖 子:23
专家分:0
注 册:2008-9-9
收藏
 问题点数:0 回复次数:5 
小程序,哪里错了?
#include <stdio.h>
#define PI 3.14159
main()
{
    float circum,totalcost,no;
    circum=area();
    totalcost=cost(circum,cost,no);
    printf("Total cost is %f\n",totalcost);
}

float area(float r, float h)
{
    printf("Input Radius:");
    scanf("%f",r);
    printf("Input Height:");
    scanf("%f",h);
    printf("Circumference of a container is %f",PI*r*r+h*2*PI*r);
    return(PI*r*r+h*2*PI*r);
}
float cost(float circum,float totalcost,float no)
{
    printf("Input Quantity:");
    scanf("%f",&no);
    printf("Input cost per cm^2:");
    scanf("%f",&cost);
    printf("Cost of each container is %f\n",circum*cost);
    totalcost=circum*cost*no;
    return(totalcost);
}

定义两个函数,area涌来计算圆柱体的表面积,cost函数计算每个圆柱体的花费和总花费,
函数调用我不怎么熟悉,请问哪里错了?谢谢。
搜索更多相关主题的帖子: include return 
2008-10-08 17:01
aibmcpgy
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-10-7
收藏
得分:0 
printf("Input Quantity:");
    scanf("%f",&no);
    printf("Input cost per cm^2:");
    scanf("%f",&cost);
    printf("Cost of each container is %f\n",circum*cost);
    totalcost=circum*cost*no;
    return(totalcost);
2008-10-08 17:13
守鹤
Rank: 4
来 自:山東臨沂
等 级:贵宾
威 望:12
帖 子:337
专家分:0
注 册:2008-6-20
收藏
得分:0 
定义的函数应先声明吧,然后在定义
要么就在main()之前就定义好,否则会提示错误的

多少个日日夜夜想起你,只希望有缘再次相见
2008-10-08 18:17
kd0376
Rank: 1
等 级:新手上路
帖 子:92
专家分:0
注 册:2007-12-7
收藏
得分:0 
先定义,在使用
2008-10-08 22:16
StarWing83
Rank: 8Rank: 8
来 自:仙女座大星云
等 级:贵宾
威 望:19
帖 子:3951
专家分:748
注 册:2007-11-16
收藏
得分:0 
错误真多……改了好多,不过虽然编译过了,还是不敢运行……

建议LZ好好看书……

专心编程………
飞燕算法初级群:3996098
我的Blog
2008-10-08 22:22
mythhaha
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2008-3-17
收藏
得分:0 
#include <stdio.h>
#define PI 3.14159
float area(float r, float h);
float wcost(float circum,float cost,float no);
void main()
{
    float circum,totalcost,no,r,h,cost;
    printf("Input Radius:");
    scanf("%f",&r);
    printf("Input Height:");
    scanf("%f",&h);
    circum=area(r,h);

    printf("Input Quantity:");
    scanf("%f",&no);
    printf("Input cost per cm^2:");
    scanf("%f",&cost);
    totalcost=wcost(circum,cost,no);

    printf("Total cost is %f:\n",totalcost);
}

float area(float r, float h)
{

    printf("Circumference of a container is %f",PI*r*r+h*2*PI*r);
    return(PI*r*r+h*2*PI*r);
}
float wcost(float circum,float cost,float no)
{
    float totalcost;
    printf("Cost of each container is %f\n",circum*cost);
   totalcost=circum*cost*no;
    return(totalcost);
}
2008-10-08 23:54
快速回复:小程序,哪里错了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015104 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved