gpt4 book ai didi

c - 嵌套函数!错误。请赐教

转载 作者:行者123 更新时间:2023-11-30 20:52:01 25 4
gpt4 key购买 nike

大家能帮我解决这个c编程问题吗?我不明白为什么当我尝试编译代码时会得到嵌套函数。我总是得到 ISO 禁止嵌套函数。请帮助我理解代码。 3天。我失去理智了。我对 C 编程还是新手。谢谢!

#include<stdio.h>
#define lcost 35;
#define tax 0.85;
void readData(int* Len,int* Wid,float* Disc,float* cost);
int calcInPrice(float area,float iPrice,float cost,int Len,int Wid);
int calcSTotal(float sTotal,float Disc,float iPrice,float tDisc);
int calcTPrice(float tPrice,float ctax,float sTotal);
void printMes(int Len, int Wid);
void printCharges(float area,float cost,float iPrice,float Disc,float tDisc,float tPrice,float ctax,float sTotal);

int main(void)
{
int x;
int Len, Wid;
float item;
float area, cost, Disc, iPrice, sTotal, tDisc, tPrice, ctax;

do{
system("cls");
printf("[1] Perform\n");
printf("[2] Exit progres\n");
printf("\n\nInput Selection:");
scanf("%d", &x);

switch (x)
{
case 1:

readData(&Len,&Wid,&Disc,&cost);
calcInPrice(area,iPrice,cost,Len,Wid);
calcSTotal(sTotal,Disc,iPrice,tDisc);
printMes(Len,Wid);
printCharges(area,cost,iPrice,Disc,tDisc,sTotal,ctax,tPrice);

printf("\n\nPress any key to return to main menu");
getch();

break;

case2:
system("cls");
printf("Exiting Program");
break;

default:
printf("\n\nInvalid Selection!");
}

}while(x < 3);

void readData(int* Len,int* Wid,float* Disc,float* cost)
{

printf("Input Length of Room: ");
scanf("%d",Len);

printf("Input Width of Room: ");
scanf("%d",Wid);

printf("Input Discount of Customer: ");
scanf("%f",Disc);

printf("Input the cost per square foot: ");
scanf("%f",cost);

return;

}

int calcInPrice(float area,float iPrice,float cost,int Len,int Wid)
{
area = Len * Wid;

iPrice = (lcost * area) + (cost * area);

return;

}


int calcSTotal(float sTotal,float Disc,float iPrice,float tDisc)
{
Disc = (Disc / 100)*iPrice;
sTotal = iPrice - (tDisc);

return;
}


int calcTPrice(float tPrice,float ctax, float sTotal)
{
ctax = sTotal * tax;
tPrice = sTotal + ctax ;
}


void printMes(int Len, int Wid)
{
printf("\n\t\tMEASUREMENT\n\n");
printf("Length\t\t %d ft", Len);
printf("Width\t\t %d ft", Wid);
printf("\nArea\t\t %d square ft", Len * Wid);

return;

}

void printCharges(float area,float cost,float iPrice,float Disc,float tDisc,float tPrice,float ctax,float stotal)
{

float item = cost * area;

printf("\n\n\t\tCHARGES\n\n");

printf("DESCRIPTION\tCOST/SQ.FT.\tCHARGE");

printf("\n________\t _________\t______");

printf("\nCarpet \t%.2f \t %0.2f ",cost,item);

printf("\nLabor \t %lf \t %0.2f",lcost, area);

printf("\n\t\t\t__________");
printf("INSTALLED PRICE \t\t %.2f", iPrice);
printf("\nDiscount \t %.2f \t %.2f ",Disc,tDisc);

printf("\n\t\t\t\t______");
printf("\nSUBTOTAL\t\t\t %.2f",sTotal);
printf("\nTax\t\t\t\t %2f",ctax);
printf("\nTOTAL\t\t\t\t %.2f",tPrice);

return;

}

return 0;
}

最佳答案

您的代码如下所示:

int main(void)
{
...

void readData(int* Len,int* Wid,float* Disc,float* cost)
{
...
}

... more functions ...

void printCharges(float area,float cost,float iPrice,float Disc,float tDisc,float tPrice,float ctax,float stotal)
{
...
}

return 0;
}

这意味着您将所有函数定义(readDataprintCharges 等)“嵌套”在 main 函数中.

这是不允许的。

相反,您需要编写类似这样的内容:

int main(void)
{
...

return 0;
}

void readData(int* Len,int* Wid,float* Disc,float* cost)
{
...
}

... more functions ...

void printCharges(float area,float cost,float iPrice,float Disc,float tDisc,float tPrice,float ctax,float stotal)
{
...
}

关于c - 嵌套函数!错误。请赐教,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20310512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com