I';我无法在else语句中使用scanf()
我们可以在其他代码中使用scanf()函数吗,就像我在这段代码中使用的一样。 Bec我无法为性别变量输入值(字符)。 所以我想知道为什么我不能输入性别变量的值I';我无法在else语句中使用scanf(),c,if-statement,scanf,C,If Statement,Scanf,我们可以在其他代码中使用scanf()函数吗,就像我在这段代码中使用的一样。 Bec我无法为性别变量输入值(字符)。 所以我想知道为什么我不能输入性别变量的值 #include<stdio.h> #include<conio.h> void main() { clrscr(); int age; char s,ms; printf("Please enter M if you are married or U if you are u
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int age;
char s,ms;
printf("Please enter M if you are married or U if you are un-married\n");
scanf("%c", &ms);
if(ms=='M')
printf("\nyou are recruted");
else if(ms=='U')
{
printf("\nenter sex- A for male & B for female\n");
scanf("%c",&s);
if(s=='A')
{
printf("\nEnter your age\n");
scanf("%d",age);
if(age>30)
printf("\nYou are selected");
else
printf("\nYour age is less for this job");
}
else if(s=='B')
{
printf("\nEnter your age\n");
scanf("%d",age);
if(age>25)
printf("\nyou are recruted");
else
printf("\nyour age is less to be recruted");
}
else
{
printf("Please enter A for male or B for female");
}
}
else
{
printf("PLEASE ENTER THE CORRECT VALUE\n please enter M for Married or U for un-married");
}
getch();
}
在首次读取此扫描时输入数据时:
scanf("%c", &ms);
一个换行符保留在键盘中。要解决此问题,请在第二次扫描中添加一个空格:
scanf(" %c",&s);
这是在scanf
读取用户输入之前,使用先前用户输入(如回车
)可能留下的stdin中的任何尾随字符。还请注意,您在scanf(“%d”,age)中遗漏了&
代码>:
另请注意
#包括
#包括
int main()
{
智力年龄;
字符s,ms;
printf(“如果您已婚,请输入M;如果您未结婚,请输入U\n”);
扫描频率(“%c”、&ms);
如果(ms=='M')
printf(“\n您被重新创建”);
否则如果(ms='U')
{
printf(“\n输入性别-男性为A,女性为B”);
scanf(“%c”和“&s”);
如果(s=='A')
{
printf(“\n输入您的年龄\n”);
scanf(“%d”和年龄);
如果(年龄>30岁)
printf(“\n您被选中”);
其他的
printf(“\n您的年龄小于此工作的年龄”);
}
如果(s=='B',则为else)
{
printf(“\n输入您的年龄\n”);
scanf(“%d”和年龄);
如果(年龄>25岁)
printf(“\n您被重新创建”);
其他的
printf(“\n您的年龄小于可重新创建的年龄”);
}
其他的
{
printf(“请输入A表示男性,输入B表示女性”);
}
}
其他的
{
printf(“请输入正确的值\n请输入M表示已婚,或输入U表示未结婚”);
}
getchar();
返回0;
}
在首次读取此扫描时输入数据时读取:
scanf("%c", &ms);
一个换行符保留在键盘中。要解决此问题,请在第二次扫描中添加一个空格:
scanf(" %c",&s);
这是在scanf
读取用户输入之前,使用先前用户输入(如回车
)可能留下的stdin中的任何尾随字符。还请注意,您在scanf(“%d”,age)中遗漏了&
代码>:
另请注意
#包括
#包括
int main()
{
智力年龄;
字符s,ms;
printf(“如果您已婚,请输入M;如果您未结婚,请输入U\n”);
扫描频率(“%c”、&ms);
如果(ms=='M')
printf(“\n您被重新创建”);
否则如果(ms='U')
{
printf(“\n输入性别-男性为A,女性为B”);
scanf(“%c”和“&s”);
如果(s=='A')
{
printf(“\n输入您的年龄\n”);
scanf(“%d”和年龄);
如果(年龄>30岁)
printf(“\n您被选中”);
其他的
printf(“\n您的年龄小于此工作的年龄”);
}
如果(s=='B',则为else)
{
printf(“\n输入您的年龄\n”);
scanf(“%d”和年龄);
如果(年龄>25岁)
printf(“\n您被重新创建”);
其他的
printf(“\n您的年龄小于可重新创建的年龄”);
}
其他的
{
printf(“请输入A表示男性,输入B表示女性”);
}
}
其他的
{
printf(“请输入正确的值\n请输入M表示已婚,或输入U表示未结婚”);
}
getchar();
返回0;
}
在首次读取此扫描时输入数据时读取:
scanf("%c", &ms);
一个换行符保留在键盘中。要解决此问题,请在第二次扫描中添加一个空格:
scanf(" %c",&s);
这是在scanf
读取用户输入之前,使用先前用户输入(如回车
)可能留下的stdin中的任何尾随字符。还请注意,您在scanf(“%d”,age)中遗漏了&
代码>:
另请注意
#包括
#包括
int main()
{
智力年龄;
字符s,ms;
printf(“如果您已婚,请输入M;如果您未结婚,请输入U\n”);
扫描频率(“%c”、&ms);
如果(ms=='M')
printf(“\n您被重新创建”);
否则如果(ms='U')
{
printf(“\n输入性别-男性为A,女性为B”);
scanf(“%c”和“&s”);
如果(s=='A')
{
printf(“\n输入您的年龄\n”);
scanf(“%d”和年龄);
如果(年龄>30岁)
printf(“\n您被选中”);
其他的
printf(“\n您的年龄小于此工作的年龄”);
}
如果(s=='B',则为else)
{
printf(“\n输入您的年龄\n”);
scanf(“%d”和年龄);
如果(年龄>25岁)
printf(“\n您被重新创建”);
其他的
printf(“\n您的年龄小于可重新创建的年龄”);
}
其他的
{
printf(“请输入A表示男性,输入B表示女性”);
}
}
其他的
{
printf(“请输入正确的值\n请输入M表示已婚,或输入U表示未结婚”);
}
getchar();
返回0;
}
在首次读取此扫描时输入数据时读取:
scanf("%c", &ms);
一个换行符保留在键盘中。要解决此问题,请在第二次扫描中添加一个空格:
scanf(" %c",&s);
这是在scanf
读取用户输入之前,使用先前用户输入(如回车
)可能留下的stdin中的任何尾随字符。还请注意,您在scanf(“%d”,age)中遗漏了&
代码>:
另请注意
#i