1

Really rookie question about C...

I want the user to enter a number between 2 and 8, and if they don't, the prompt repeats itself until an integer within my parameters is entered. I can get this to work with one parameter ie

  int between_2_and_8(string prompt)
{
    int n;
    do
    {
        n = get_int("%s", prompt);
    }
    while (n > 8);
    return n;
}

but not having luck putting 2 parameters in. Here is the snippet:

int between_2_and_8(string prompt)
{
    int n;
    do
    {
        n = get_int("%s", prompt);
    }
    while (n > 8);
    return n;

    while (n < 2);
    return n;

}

1 Answer 1

1

This worked

while (n > 8 || n < 2)
1
  • 1
    Congratulations on figuring it out on your own! Any statement that has a test, like an if or a while statement, can have multiple tests. The simple tests are combined into complex tests using ANDs, ORs, and parentheses. You'll get plenty of practice throughout the course! ;-)
    – Cliff B
    Jan 17, 2019 at 4:28

You must log in to answer this question.

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