C新手,希望将结构传递给函数,然后将值返回给main。谢谢你的帮助
这段代码应该获取结构的成员,并获取函数中每个成员的值。然后,将值传递给main()并向用户显示信息。我正试图建立一个更大的计划,这是一个非常重要的部分。我经常遇到一些错误,主要是函数错误。错误如下: main.c:18:1: warning: return type defaults to ‘int’ [-Wimplicit-int] final_expenses(struct expense) ^~~~~~~~~~~~~~ main.c: In function ‘final_expenses’: main.c:21:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token { ^ main.c:30:32: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token struct expenses expense_total(){ ^ main.c:18:1: error: old-style parameter declarations in prototyped function definition final_expenses(struct expense) ^~~~~~~~~~~~~~ main.c:18:23: error: parameter name omitted final_expenses(struct expense) ^~~~~~~ main.c:63:1: error: expected ‘{’ at end of input } ^ main.c:18:1:警告:返回类型默认为'int'[-Wimplicit int] 最终费用(结构费用) ^~~~~~~~~~~~~~ main.c:在“最终费用”功能中: main.c:21:1:错误:应为“=”,“,”,“;”,”“{”标记前的asm”或“{”属性 { ^ main.c:30:32:错误:应为“=”、“、”、“;”、“asm”或“{”标记前面的“{”属性 结构费用费用总额(){ ^ main.c:18:1:错误:原型函数定义中的旧式参数声明 最终费用(结构费用) ^~~~~~~~~~~~~~ main.c:18:23:错误:忽略参数名称 最终费用(结构费用) ^~~~~~~ main.c:63:1:错误:输入末尾应为“{” } ^C新手,希望将结构传递给函数,然后将值返回给main。谢谢你的帮助,c,function,struct,C,Function,Struct,这段代码应该获取结构的成员,并获取函数中每个成员的值。然后,将值传递给main()并向用户显示信息。我正试图建立一个更大的计划,这是一个非常重要的部分。我经常遇到一些错误,主要是函数错误。错误如下: main.c:18:1: warning: return type defaults to ‘int’ [-Wimplicit-int] final_expenses(struct expense) ^~~~~~~~~~~~~~ main.c: In function ‘final_expens
#包括
/*函数的结构*/
类型定义结构费用{
浮动壳体;
漂流回家;
浮子气;
浮动车费;
浮车;
漂浮食物;
浮动公用设施;
浮动wifi;
浮动贷款支付;
浮动电话费;
浮动储蓄;
花车娱乐;
}费用;
最终费用(结构费用)
int main()
{
最终费用;
s=最终费用();
printf(“\t\t\t预算跟踪程序:”);
printf(“最终费用总额为:%*f”,最终费用);
返回0;
}
/*用于计算总费用的函数*/
结构费用费用总额(){
结构费用;
浮动最终费用;
printf(“您的住房费用是多少?”);
scanf(“%f”和费用、住房);
printf(“您的家庭保险费是多少?”);
scanf(“%f”和expenses.home_-ins);
printf(“你付多少汽油钱?”);
scanf(“%f”和费用.气体);
printf(“你付多少车费?”);
scanf(“%f”和费用。车费);
printf(“您的汽车保险费是多少?”);
scanf(“%f”和费用、车辆);
printf(“你花多少钱买食物?”);
scanf(“%f”和费用、食品);
printf(“您的水电费是多少?”);
scanf(“%f”和expenses.utilities);
printf(“您的wifi费用是多少?”);
scanf(“%f”和expenses.wifi);
printf(“您的贷款支付额是多少?”);
scanf(“%f”和费用、贷款和付款);
printf(“您的电话费是多少?”);
scanf(“%f”和费用、电话费和账单);
printf(“你的储蓄要付多少钱?”);
scanf(“%f”和费用节省);
printf(“您的娱乐费用是多少?”);
scanf(“%f”和费用、娱乐);
/*总费用的实际计算代码*/
最终支出=支出。住房+支出。住房+支出。汽油+支出。汽车支付+支出。汽车支付+支出。食品+支出。公用事业+支出。无线网络+支出。贷款支付+支出。电话账单+支出。储蓄+支出。娱乐;
返回最终费用;
}
最终费用(结构费用)
需要一个;
s
需要定义。struct
后表示最终费用(结构费用)
的行需要返回类型(要么结构费用
要么费用
)和分号。final\u expenses;
内的main()
行几乎没有意义-如果final\u expenses()的声明
是固定的。您没有定义s
。函数返回struct expenses
,但您定义了struct expense
。列表继续。。。
#include <stdio.h>
/* Struct for the function */
typedef struct expense{
float housing;
float home_ins;
float gas;
float car_pay;
float car_ins;
float food;
float utilities;
float wifi;
float loan_pay;
float phone_bill;
float savings;
float entertainment;
} expenses;
final_expenses(struct expense)
int main()
{
final_expenses;
s = final_expenses();
printf("\t\t\tBudget Tracker: ");
printf("Final expenses total out to be: %*f", final_expenses);
return 0;
}
/*Function for calculating the total expense */
struct expenses expense_total(){
struct expenses;
float final_expenses;
printf("How much do you pay for your housing? ");
scanf("%f", &expenses.housing);
printf("How much do you pay for your home insurance? ");
scanf("%f", &expenses.home_ins);
printf("How much do you pay for gas? ");
scanf("%f", &expenses.gas);
printf("How much do you pay for your car payment? ");
scanf("%f", &expenses.car_pay);
printf("How much do you pay for your car insurance? ");
scanf("%f", &expenses.car_ins);
printf("How much do you pay for your food? ");
scanf("%f", &expenses.food);
printf("How much do you pay for your utilities? ");
scanf("%f", &expenses.utilities);
printf("How much do you pay for your wifi? ");
scanf("%f", &expenses.wifi);
printf("How much do you pay for your loan payment? ");
scanf("%f", &expenses.loan_pay);
printf("How much do you pay for your phone bill? ");
scanf("%f", &expenses.phone_bill);
printf("How much do you pay for your savings? ");
scanf("%f", &expenses.savings);
printf("How much do you pay for your entertainment? ");
scanf("%f", &expenses.entertainment);
/* Code for the actual calculation of the total expense */
final_expense = expenses.housing + expenses.home_ins + expenses.gas + expenses.car_pay + expenses.car_ins + expenses.food + expenses.utilities + expenses.wifi + expenses.loan_pay + expenses.phone_bill + expenses.savings + expenses.entertainment;
return final_expenses;
}