0

So, I think I'm almost there with this problem, just after answering prompt it doesn't return any value, in fact it keeps letting me type.

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

int main(void)
{
    // TODO: Prompt for start size
    int s;
    do
    {
    s = get_int("Starting size ?");
    }
    while (s<9);
    // TODO: Prompt for end size
    int e;
    do
    {
    e = get_int("Ending size ?");
    }
    while (e<s);
    // TODO: Calculate number of years until we reach threshold
    int y=0;
    do
    {
    y = s + (s/3) - (s/4);
    y++;
    }
    while (s<e);
    // TODO: Print number of years
    printf("%i", y);
}

1 Answer 1

1

Look at the loop:

int y=0;
do
{
y = s + (s/3) - (s/4);
y++;
}
while (s<e);

This is an infinite loop. s never changes so if s is less than e on the first pass, it will run forever. maybe that was supposed to be s++ and not y++? Or maybe the code inside the loop is just flawed? I haven't had my morning coffee, so I'm not awake to do a deep dive on it. ;-)

It's not so much that it's letting you keep typing, it's in a loop ignoring your input while you type.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .