M
M
Michael2019-03-04 18:35:06
C++ / C#
Michael, 2019-03-04 18:35:06

Produces incorrect result. Where is the mistake?

Explain to the blind man why the program below displays either "C" or nothing, empty, emptiness, 0.
The task is this:
5c7d454310593624194141.png
And here is the code itself:

int main()
{
    float x, y, r1, r2, t;

    printf("r1 = ");
    scanf("%d", &r1);
    printf("r2 = ");
    scanf("%d", &r2);
    printf("x = ");
    scanf("%d", &x);
    printf("y = ");
    scanf("%d", &y);

    t = (x * x)+ (y * y);
   
    if (t > r2*r2) printf("D");
    else if (t > r1*r1)
    {
        if (x > 0 && y > 0) printf("D");
        else printf("B");
    }
    else if (t < r1*r1)
    {
        if (x > 0 && y > 0) printf("C");
        else printf("A");
    }

    return 0;
}

As I understand it, depending on the given coordinates, you need to find the area under which these coordinates fall and display "A", "B', "C" or "D".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2019-03-04
@GavriKos

Go through the debugger. At least check that your input is correct.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question