gpt4 book ai didi

c - 带 if 语句的函数

转载 作者:太空宇宙 更新时间:2023-11-04 07:34:29 24 4
gpt4 key购买 nike

大家好,我是编程新手。我知道函数的工作原理和 if 语句,所以我想知道如何在函数中编写 if & else 语句并向用户显示答案。可能没有任何 goto 语句

代码如下:

  if(year < 1583) //considers if a year input is less than 1583 which is the starting year for this calendar
{
printf("\n\nPlease select a year after 1583 \n\n");
goto YEAR;
system("cls");
}
if(Leap_year(year))//if statement calls Leap Year function
{
printf("\t ======================= \n");
printf("\t* THIS IS A LEAP YEAR *\n");
printf("\t ======================= \n\n");
}
else {
printf("\t ======================= \n");
printf("\t* THIS IS NOT A LEAP YEAR *\n");
printf("\t ======================= \n\n");
}

最佳答案

无论是 C 还是 C#,都可以使用 while 循环来解决。

do
{
// You need to prompt for year here. Your code doesn't show how you do that.
if (year < 1583)
{
printf("\n\nPlease select a year after 1583 \n\n");
// Note: The user will never see the printf above if you clear the screen right after
system("cls");
}
} while (year < 1583);

关于c - 带 if 语句的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10219668/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com