c语言 大括号问题

#include<stdio.h>#include<stdlib.h>#include<math.h>//指针数组//voidchange(intpay,intcost)... #include <stdio.h>
#include <stdlib.h>
#include <math.h>
//指针数组
//void change(int pay,int cost) //pay付的钱,cost消费额,单位元

int *p[7];
int a,b,c,d,e,f,g;
int pay;
int cost;
{ if(chan==0)
{
a=0; b=0; c=0;d=0;e=0;f=0;g=0;
}
else
{
a=chan/1000;
b=(chan%1000)/500;
c=(chan%500)/100;
d=(chan%100)/50;
e=(chan%50)/10;
f=(chan%10)/5;
g=chan%10;

/*a=chan/100;
b=(chan%100)/10;
c=chan%10;*/

}}
p[0]=&a; p[1]=&b; p[2]=&c; p[3]=&d; p[4]=&e; p[5]=&f; p[6]=&g;

int main()
{
double pay,cost;
printf("实付:");
scanf("%f",&pay);
printf("应收:");
scanf("%f",&cost);
change(pay,cost);
printf("找零:%d个1000元%d个500元%d个100元%d个50元%d个10元%d个5元%d个一元\n",*p[0],*p[1],*p[2],*p[3],*p[4],*p[5],*p[6]);
system("PAUSE");
return 0;
}
//编译的时候一直提示第一个花括号有问题,请各位帮我检查一下到底花括号有什么问题
展开
 我来答
yunxiaorun
2015-12-26 · TA获得超过393个赞
知道小有建树答主
回答量:208
采纳率:0%
帮助的人:78.3万
展开全部
在C中,使用大括号的方法无所谓对还是错——只要每个开括号后都有一个闭括号,程序中就不再会出现与大括号有关的问题。然而,有三种著名的大括号格式经常被使用:
Kernighan和Ritchie,Allman,Whitesmiths。下文中将讨论这三种格式。

在《C程序设计语言(The C Programming Language)》一书中,Brian Kernighan和Dennis Ritchie介绍了所使用的大括号格式,这种格式如下所示:
if (argc<3) {
printf (" Error! Not enough arguments. Correct usage is ..\n" ) ;
printf("c:>eopyfile <source_file> <destination_file>\n") ;
exit (1) ;
}
else {
open_files () ;
while (! feof(infile)) {
read_data ( ) ;
write_data() ;
}
close files() ;
}

注意,在Kb&R格式中,开括号总是与使用它的语句在同一行上,而闭括号总是在它所关闭的语句的下一行上,并且与该语句对齐。例如,在上例中,if语句的开括号和它在同一行上,if语句的闭括号在它的下一行上,并且与它对齐。在与if语句对应的else条件语句以及出现在程序段后部的while语句中,情况也是这样的。

下面是用Allman格式书写的同一个例子:
if (argc<3)
{
printf("Error! Not enough arguments. Correct usage is :\n" ) ;
printf("C:>copyfile <source_file> <destination_file>\n") ;
exit(1);
}
else
{
open_files ( );
while (! feof(infile))
{
read_data ( ) ;
write data();
}
close_files() ;
}
注意,在Allman格式中,每个大括号都单独成行,并且开括号和闭括号都与使用的语句对齐。

下面是用Whitesmiths格式书写的同一个例子:
if (argc<3)
{
printf("Error! Not enough arguments, Correct usage is :\n" );
printf ("C :> copyfile<source_file><destination_file>\n." ) ;
exit(1);
}
else
{
open files () ;
while (! feof(infile))
{
read_data() ;
write data();
}
close files () ;
}
与Allman格式相同,Whitesmiths格式也要求大括号单独成行,但是要和所包含的语句对齐。例如,在上例中,if语句的开括号是与第一个printf()函数调用对齐的。

不管使用哪一种格式,一定要保持前后一致——这将有助于自己或其它人更方便地读程序。
dwjchdu
2011-10-25 · TA获得超过5914个赞
知道大有可为答主
回答量:4576
采纳率:60%
帮助的人:1061万
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//指针数组
//void change(int pay,int cost) //pay付的钱,cost消费额,单位元
void change(int pay,int cost) {
int *p[7];
int a,b,c,d,e,f,g;
int pay;
int cost;
{ if(chan==0)
{
a=0; b=0; c=0;d=0;e=0;f=0;g=0;
}
else
{
a=chan/1000;
b=(chan%1000)/500;
c=(chan%500)/100;
d=(chan%100)/50;
e=(chan%50)/10;
f=(chan%10)/5;
g=chan%10;

/*a=chan/100;
b=(chan%100)/10;
c=chan%10;*/

}}
p[0]=&a; p[1]=&b; p[2]=&c; p[3]=&d; p[4]=&e; p[5]=&f; p[6]=&g;
}
int main()
{
double pay,cost;
printf("实付:");
scanf("%f",&pay);
printf("应收:");
scanf("%f",&cost);
change(pay,cost);
printf("找零:%d个1000元%d个500元%d个100元%d个50元%d个10元%d个5元%d个一元\n",*p[0],*p[1],*p[2],*p[3],*p[4],*p[5],*p[6]);
system("PAUSE");
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
杀鬼
2011-10-25 · TA获得超过357个赞
知道小有建树答主
回答量:331
采纳率:0%
帮助的人:270万
展开全部
你上面的函数叫啥 名,,在哪里定义的?
函数后面没有大括号 你没看见?
还有很多错误 ,你追问我再说~~~
算了 我没时间等你了,,
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//指针数组
int *p[7];
int a,b,c,d,e,f,g;
void change(double pay,double cost) //pay付的钱,cost消费额,单位元
{

int chan=pay-cost;
if(chan==0)
{
a=0; b=0; c=0;d=0;e=0;f=0;g=0;
}
else
{
a=chan/1000;
b=(chan%1000)/500;
c=(chan%1000%500)/100;
d=(chan%1000%500%100)/50;
e=(chan%1000%500%100%50)/10;
f=(chan%1000%500%100%50%10)/5;
g=chan%1000%500%100%50%10%5;

/*a=chan/100;
b=(chan%100)/10;
c=chan%10;*/

}
p[0]=&a; p[1]=&b; p[2]=&c; p[3]=&d; p[4]=&e; p[5]=&f; p[6]=&g;
}
int main()
{
double pay,cost;
printf("实付:");
scanf("%lf",&pay);
printf("应收:");
scanf("%lf",&cost);
change(pay,cost);
printf("找零:%d个1000元\n%d个500元\n%d个100元\n%d个50元\n%d个10元\n%d个5元\n%d个一元\n",*p[0],*p[1],*p[2],*p[3],*p[4],*p[5],*p[6]);
system("PAUSE");
return 0;
}
稍微改了一下,能运行 ,你自己看吧,,能学多少 看你自己了,,因为你弄的类型不好搞,double的不好弄
更多追问追答
追问
不用double也行吧? 我这只是个简单的找零钱的程序,用int应该也行吧? 因为我编的这个是台币的找零,台币里面没有角和分,所以应该可以用int。
追答
那你就把所有double都改成int吧,,,,还在scanf("%lf",..);和printf();里面的也都改了,,改成%d
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
雨雁菱06M
2011-10-25 · TA获得超过2040个赞
知道小有建树答主
回答量:944
采纳率:100%
帮助的人:819万
展开全部
{ if(chan==0)
{
a=0; b=0; c=0;d=0;e=0;f=0;g=0;
}
else
{
a=chan/1000;
b=(chan%1000)/500;
c=(chan%500)/100;
d=(chan%100)/50;
e=(chan%50)/10;
f=(chan%10)/5;
g=chan%10;

/*a=chan/100;
b=(chan%100)/10;
c=chan%10;*/

}}
这个是函数么?是函数的话怎么连函数名都没有?如果不是函数想直接这么用事不行的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
天天Uas
2011-10-25
知道答主
回答量:24
采纳率:0%
帮助的人:10.7万
展开全部
你定义的变量全在外边这是用啥编呢啊?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式