简体   繁体   中英

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.

You are assigning the requested integers to variables s and e , and so you can print them out later.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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