#include<stdio.h>
#include<stdlib.h>
int suanqian(int,int);
main(){
start: int i,a,b,c,need,put,rest;
int price[10]={1,2,2,3,4,6,6,6,6,6};
char*name[10]={“怡宝”,”可乐”,”雪碧”,”酸奶”,”橙汁”,”咖啡”,”红牛”,”脉动”,”芬达”,”奶茶”};
for(i=0;i<10;i++){
printf(“%d.%s”,i+1,name[i]);printf(” %d元\n”,price[i]);
}
bianhao:printf(“请输入物品的编号”);
scanf(“%d”,&a);
if(a>10){
printf(“输入有误,请重新输入\n”);
goto bianhao;
}
system(“CLS”);printf(“您选择了%s”,name[a-1]);
printf(“\n请输入物品的数量”);
scanf(“%d”,&b);
int suanqian(int x,int y){
int z;
z=x*a;
return z;
}
need=suanqian(b,price[i-1]);
printf(“所需费用%d元”,need);
buzu:printf(“请投币”);
scanf(“%d”,&put);
if(put==need)
{printf(“谢谢惠顾”);}
else if(put<need)
{printf(“支付余额不足,退回%d元\n”,put);goto buzu;}
else if(put>need){
rest=put-need;
printf(“找回零钱%d元,谢谢惠顾”,rest);}
printf(“继续消费请输入0,结束消费请输入1”);
scanf(“%d”,&c);if(c==0){system(“CLS”);goto start;}
return 0;}
int suanqian(int x,int y){
int z;
z=x*a;
return z;
这里总提示本人函数定义非法为什么啊。本人不会改。有劳各位高手。
#include<stdlib.h>
int suanqian(int,int);
main(){
start: int i,a,b,c,need,put,rest;
int price[10]={1,2,2,3,4,6,6,6,6,6};
char*name[10]={“怡宝”,”可乐”,”雪碧”,”酸奶”,”橙汁”,”咖啡”,”红牛”,”脉动”,”芬达”,”奶茶”};
for(i=0;i<10;i++){
printf(“%d.%s”,i+1,name[i]);printf(” %d元\n”,price[i]);
}
bianhao:printf(“请输入物品的编号”);
scanf(“%d”,&a);
if(a>10){
printf(“输入有误,请重新输入\n”);
goto bianhao;
}
system(“CLS”);printf(“您选择了%s”,name[a-1]);
printf(“\n请输入物品的数量”);
scanf(“%d”,&b);
int suanqian(int x,int y){
int z;
z=x*a;
return z;
}
need=suanqian(b,price[i-1]);
printf(“所需费用%d元”,need);
buzu:printf(“请投币”);
scanf(“%d”,&put);
if(put==need)
{printf(“谢谢惠顾”);}
else if(put<need)
{printf(“支付余额不足,退回%d元\n”,put);goto buzu;}
else if(put>need){
rest=put-need;
printf(“找回零钱%d元,谢谢惠顾”,rest);}
printf(“继续消费请输入0,结束消费请输入1”);
scanf(“%d”,&c);if(c==0){system(“CLS”);goto start;}
return 0;}
int suanqian(int x,int y){
int z;
z=x*a;
return z;
这里总提示本人函数定义非法为什么啊。本人不会改。有劳各位高手。
解决方案
80
1.不是深层嵌套一般不推荐使用goto
2.suanqian函数里z=x*a;应该是z=x*y;吧
3.别在函数里定义函数
2.suanqian函数里z=x*a;应该是z=x*y;吧
3.别在函数里定义函数
#include<stdio.h> #include<stdlib.h> int suanqian(int,int); int main(){ start: int i,a,b,c,need,put,rest; int price[10]={1,2,2,3,4,6,6,6,6,6}; char*name[10]={"怡宝","可乐","雪碧","酸奶","橙汁","咖啡","红牛","脉动","芬达","奶茶"}; for(i=0;i<10;i++){ printf("%d.%s",i+1,name[i]);printf(" %d元\n",price[i]); } bianhao:printf("请输入物品的编号"); scanf("%d",&a); if(a>10){ printf("输入有误,请重新输入\n"); goto bianhao; } system("CLS");printf("您选择了%s",name[a-1]); printf("\n请输入物品的数量"); scanf("%d",&b); need=suanqian(b,price[i-1]); printf("所需费用%d元",need); buzu:printf("请投币"); scanf("%d",&put); if(put==need) {printf("谢谢惠顾");} else if(put<need) { printf("支付余额不足,退回%d元\n",put);goto buzu; } else if(put>need){ rest=put-need; printf("找回零钱%d元,谢谢惠顾",rest); } printf("继续消费请输入0,结束消费请输入1"); scanf("%d",&c);if(c==0){system("CLS");goto start;} return 0; } int suanqian(int x,int y){ int z; z=x*y; return z; }