Answer the question
In order to leave comments, you need to log in
Calculate whether a point falls within the shaded area?
Hello everyone, there is a code that does not work correctly in the condition, could you point out errors
#include "stdafx.h"
#include "iostream"
#include <conio.h>
using namespace std;
int main()
{
int x, y, R=7, K=30;
cout << "x=";
cin >> x;
cout << "y=";
cin >> y;
if ((x >= -K && y >= -K && (x + K)*(x + K) + (y + K)*(y + K) <= 4 * K*K)
&& !(y > -x && y*y + x*x < R*R));
else
cout << "Toshka ne popadaet";
return 0;
}
Answer the question
In order to leave comments, you need to log in
Separate the scope of the logical if block explicitly with curly braces.
Divide the conditions into component parts, but do it better with separate variables, i.e.
bool isXPosRightThanLine1 = (x >= -K);
bool isYPosUpperThanLine1 = (y >= -K);
...
if (isPointInArea(x,y))
{
//do something
}
else
{
//do something else
}
math.h
library for mathematical calculations,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question