首页新闻找找看学习计划

为什么这样就是未初始化的局部变量

0
[待解决问题]

include<stdio.h>

void homework01(int age)
{
printf("请输入年龄:");
scanf("%d", &age);
if (age >= 18)
{ printf("成年\n"); }
else { printf("未成年\n"); }
}
void homework02(int day)
{
printf("请输入:");
scanf("%d", &day);
if (day >= 1 && day <= 5)
{ printf("工作日\n"); }
else if (day == 6 || day == 7)
{ printf("休息日\n"); }
else { printf("输入有误\n"); }
}
void homework03(int month)
{
printf("请输入月份:");
scanf("%d", &month);
if (month == 3 || month == 4 || month == 5)
{ printf("%d月为春季\n", month); }
else if (month == 6 || month == 7 || month == 8)
{
printf("%d月为夏季\n", month);
}
else if (month == 9 || month == 10 || month == 11)
{
printf("%d月为秋季\n", month);
}
else if(month==12||month==1||month==2)
{ printf("%d月为冬季\n"); }
else { printf("输入有误\n"); }
}
void homework04(int x)
{
float y; printf("请输入一个整数:");
scanf("%d", &x);
if (x >= 25)
{ y = (float)x / 3 + x / 2; printf("f(x)=%f\n", y);}
else if (x >= 0 && x < 25)
{ y = x*x; printf("f(x)=%f\n", y);}
else { y = -x; printf("f(x)=%f\n", y); }
}
void main()
{ int age;
homework01(age);
int day;
homework02(day);
int month;
homework03(month);
int x;
homework04(x);
}

gbcjhdiwjsn的主页 gbcjhdiwjsn | 菜鸟二级 | 园豆:202
提问于:2019-11-19 12:12
< >
分享
所有回答(1)
0

你的主函数中,age,day,month,x都需要赋初值,不然就会报错

wwr01 | 园豆:613 (小虾三级) | 2019-11-21 09:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册