【发布时间】:2018-10-26 17:28:39
【问题描述】:
参数没有通过 if 语句,我不知道为什么。
在某些情况下,考虑到您对 Continents 的预期寿命估计,该程序应该给您“您还有多少年?”。
您输入的参数是:年龄、大陆和性别。当我执行它时,我可以输入参数,然后它就停止工作了。
#include<stdio.h>
int main(){
unsigned char gender,cont; //cont=Continent
char male,female,America,Oceania,Europe,Africa,Asia;
int age,le; //le=Life expectancy
printf("Insert Continent\n");
scanf("%s",&cont);
printf("Insert Gender\n");
scanf("%s",&gender);
printf("Insert Age\n");
scanf("%d",&age);
//for females
if (gender==female) {
if(cont==America) {
if(80-age<0) {
le=80-age;
printf("Outlived life expectancy by:\t",le);
} else {
le=80-age;
printf("You are expected to live ",le," more years");
}
}
if(cont==Oceania) {
if(80-age<0) {
le=80-age;
printf("Outlived life expectancy by:\t",le);
} else {
le=80-age;
printf("You are expected to live ",le," more years");
}
}
if(cont==Europe) {
if(82-age<0) {
le=82-age;
printf("Outlived life expectancy by:\t");
} else {
le=82-age;
printf("You are expected to live ",le," more years");
}
}
if(cont==Asia) {
if(74-age<0) {
le=74-age;
printf("Outlived life expectancy by:\t");
} else {
le=74-age;
printf("You are expected to live ",le," more years");
}
}
if(cont==Africa) {
if(64-age<0) {
le=64-age;
printf("Outlived life expectancy by:\t");
} else {
le=64-age;
printf("You are expected to live ",le," more years");
}
}
}
return 0;
}
【问题讨论】:
-
如果是男性,程序将退出,您只会捕捉到女性性别
-
主程序中也有男性部分,但它会长两倍,所以我想我会发布一半,因为它基本上是重复的
-
性别是否可能区分大小写?或者你有一个菜单选择来确保不会发生这种情况
-
什么是
cont==America等。应该怎么做? -
您是否为与某处比较的变量设置了值?我在这段代码的任何地方都看不到它们
标签: c