I’m trying to compare data from one file to another to see if it “fits” inside the other. I’m thinking of one set as “Holes” and the other as “Blocks.” I’m trying to see if all circle blocks fit inside at least one circle hole. If they all fit, I want to output “YES.” If one does not fit, I want to output “NO, all circle blocks do not fit into at least one hole.”
Heres my code:
bool fits = false;
for (int i=0; i<M; i++)
{
if (btype[i] == Circles)
{
CA[i] = (3.14 * (D[i] * D[i]));
}
for (int j=0; j<N; j++)
{
if (htype[j] == Circle)
{
CA[j] = (3.14 * (A[j] * A[j]));
}
if (CA[i] < CA[j])
{
fits = true;
break;
}
}
if (!fits)
{
break;
}
}
if (fits)
{
cout << "5. YES, all circle blocks fit a hole. "
<< endl;
}
else
{
cout << "5. NO, all circle blocks don't fit a hole. "
<< endl;
}
The code is not acting right. When I put a circle value into the input file that should definitely make the program cout a NO, it give me a YES. I can’t figure it out.
You have the if statement that does the printing inside the last for loop.
If you want to print the message depending on if one doesn’t fit, and if all fit then print another message you can do it like this.