I am trying to find the area and perimeter of a Circle using multiple files. I keep getting an error for no declaration matches. I have been working on this for over a week and cannot figure out what I am doing wrong.
cout << "----------------------------------------------" << endl << endl;
cout << "Calculations for a Circle" << endl << endl;
cout << "----------------------------------------------" << endl << endl;
cout << "Let's find the Area and Perimeter of a Circle:" << endl;
cout << endl;
cout << "Enter the radius for the Circle: ";
cin >> radius;
cout << endl;
try{
if(radius ==0)
{
throw 99;
}
Circle cir{10};
cir.getRadius();
}
catch(float x)
{
cout <<"EXCEPTION: You cannot use 0 as your radius";
}
cout << "The area of the circle is: " << cir.getArea() << "\n\n";
cout << endl;
cout << "AND" << "\n\n"<< endl;
cout << "The perimeter of the circle is: " << cir.getPerimeter() << "\n\n";
cout << endl;
Circle cir is declared within the scope of the try block. It is not visible to the logic in your catch block or outer code.
Are you required to use exceptions here for academic purposes? If not, I would just change your logic into an if/else chain.
1 2 3 4 5 6 7 8 9 10 11 12 13
cin >> radius;
if (radius == 0)
{
cout << "You cannot use 0 as your radius\n";
}
else
{
Circle cir{10};
cout << "The area of the circle is: " << cir.getArea() << "\n\n";
cout << endl;
cout << "AND" << "\n\n"<< endl;
cout << "The perimeter of the circle is: " << cir.getPerimeter() << "\n\n\n";
}
Alternatively, you could have the constructor of Circle throw.