在C中自动再次运行代码

在C中自动再次运行代码,c,C,如果最初输入的值小于0或大于23,我希望用户能够立即重新输入另一个值。当前,我的代码输出“请重新输入小于24的值”并停止。然后必须再次运行它,用户才能重新输入另一个值 { printf ("What is the height of the half-pyramids?\n"); int height = get_int(); if (height>23) { printf("please re-enter a

如果最初输入的值小于0或大于23,我希望用户能够立即重新输入另一个值。当前,我的代码输出“请重新输入小于24的值”并停止。然后必须再次运行它,用户才能重新输入另一个值

{
    printf ("What is the height of the half-pyramids?\n");
        int height = get_int();
        if (height>23)
        {
            printf("please re-enter a value less than 24\n");
        }
        else if (height<0)
        {
            printf("please re-enter a value more than 0\n");
        }
        else
        {
            printf("%i", height);
    }

}
{
printf(“半金字塔的高度是多少?\n”);
int height=get_int();
如果(高度>23)
{
printf(“请重新输入一个小于24\n的值”);
}
否则,如果(高度使用循环

while(1) {
    printf ("What is the height of the half-pyramids?\n");
    int height = get_int();
    if (height>23)
    {
        printf("please re-enter a value less than 24\n");
    }
    else if (height<0)
    {
        printf("please re-enter a value more than 0\n");
    }
    else
    {
        printf("%d\n", height);
        break; // stop stop looping
}
while(1){
printf(“半金字塔的高度是多少?\n”);
int height=get_int();
如果(高度>23)
{
printf(“请重新输入一个小于24\n的值”);
}

否则,如果(高度您可以使用do while循环:

do {
    printf ("What is the height of the half-pyramids?\n");
    int height = get_int();
    if (height > 23) {
        printf("please re-enter a value less than 24\n");
    } else if (height <= 0) {
        printf("please re-enter a value more than 0\n");
    }
    else {
        printf("%i", height);
    }
} while (height <= 0 || height > 23);
do{
printf(“半金字塔的高度是多少?\n”);
int height=get_int();
如果(高度>23){
printf(“请重新输入一个小于24\n的值”);

}else if(height)使用
while(1)
循环。当用户的输入有效时中断。对不起,你介意给出一个更详细的例子吗?我对this@noviceengineer13读一本介绍c语言基础知识的书而不是在这里提问怎么样?好吧,对不起,我的错!我猜你是对的@user0042