简体   繁体   English

为什么我的程序没有提示输入最终值? [C]

[英]How come my program doesn't prompt for the end value? [C]

#include <cs50.h>
#include <stdio.h>

int main(void)
{
    {
        // TODO: Prompt for start size
        int s;
        do
        {
            s = get_int("Starting_value: ");
        } while (s < 9);
        return s;
    }
    // TODO: Prompt for end size
    int e; 
    do 
    {
        e = get_int("End_value: ");
    } while ("e < s");
    return e;
    // TODO: Calculate number of years until we reach threshold
        
    // TODO: Print number of years
}

I was wondering why my program doesn't prompt me for the end value when I run it, I'm new to programming so the answer might just be obvious.我想知道为什么我的程序在运行时没有提示我输入最终值,我是编程新手,所以答案可能很明显。 I've tried renaming the variables but that didn't work.我试过重命名变量,但没有奏效。 The first part of the program works as intended, where it prompts for the starting size, just it doesn't prompt for end size.程序的第一部分按预期工作,它提示输入起始大小,只是不提示输入结束大小。 Thanks.谢谢。

The best advice I can provide here is that you don't need to use return at all for this piece of code.我可以在这里提供的最好建议是,您根本不需要为这段代码使用return

You are assigning the requested integers to variables s and e , and so you can print them out later.您正在将请求的整数分配给变量se ,因此您可以稍后将它们打印出来。

Once something is returned, the function ends right there and then, and since you only have one main function, your whole program ends as soon as something is returned.一旦返回某些内容,function 就会立即结束,并且由于您只有一个main的 function,因此一旦返回某些内容,您的整个程序就会结束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM