C菜单-否则如果
我是C语言的新手,我需要为一个项目构建一个带有循环的菜单。 我有两个问题 1我想在else中添加一个字符,如果在主菜单上按2后询问某个问题,问题将是您是否要参加活动?用户可以输入聊天Y或N,然后程序将感谢用户并中断,其他输入将用户发送到主菜单 2当我在主菜单上按3时,我想计算程序的循环次数,我不知道如何将计数选项与else if组合C菜单-否则如果,c,C,我是C语言的新手,我需要为一个项目构建一个带有循环的菜单。 我有两个问题 1我想在else中添加一个字符,如果在主菜单上按2后询问某个问题,问题将是您是否要参加活动?用户可以输入聊天Y或N,然后程序将感谢用户并中断,其他输入将用户发送到主菜单 2当我在主菜单上按3时,我想计算程序的循环次数,我不知道如何将计数选项与else if组合 int choice; while (1) { printf("Main Menu\n"); printf("\n"); printf(
int choice;
while (1)
{
printf("Main Menu\n");
printf("\n");
printf("Please enter num:");
scanf("%d", &choice);
printf("You entered %d\n", choice);
if (choice == 4)
{
break;
}
else if (choice == 1)
printf("Returned to main menu\n");
else if (choice == 2)
printf("Are you going to the event?\n");
else if (choice == 3)
printf("number of loops that made are \n");
else if (choice == 4)
printf("Bye!\n");
else
printf("Wrong Input!\n");
}
printf("Bye!\n");
return 0;
}对于计数循环问题,只需创建一个int变量,并在每个循环结束时向其添加1。 e、 g 对于另一个问题,您可以使用
else if(choice==2)
{
char going;
printf("Are you going to the event? Y/N");
scanf("%c",&going);
if(going=='N'||going=='n')
*code*
system("PAUSE");
return 0;
else if(going=='Y'||going=='y')
{
*code*
}
}
对于1-我认为我需要添加for循环,但是短语已经在else if循环中了。
else if(choice==2)
{
char going;
printf("Are you going to the event? Y/N");
scanf("%c",&going);
if(going=='N'||going=='n')
*code*
system("PAUSE");
return 0;
else if(going=='Y'||going=='y')
{
*code*
}
}