Design an algorithm that asks for the radius of two
circles. The algorithm should tell the user which circle has the greater area, or whether the areas
are the same.
#include <iostream>
int main()
{
    //The area of a circle is directly proportional to the radius, 
    //therefore there is no need to calculate the area itself for comparison
    double r1;
    double r2;
    std::cout<<"Enter the radius of the first circle: ";
    std::cin>>r1;
    std::cout << "Enter the radius of the second circle: ";
    std::cin >> r2;
    if (r1 < 0 || r2 < 0) 
    {
        std::cout << "Invalid data entered. Radius cannot be negative." << std::endl;
    }
    else if (r1 > r2) 
    {
        std::cout<< "The area of the first circle is greater than the area of the second circle" << std::endl;
    }
    else if (r2 > r1)
    {
        std::cout << "The area of the second circle is greater than the area of the first circle" << std::endl;
    }
    else
    {
        std::cout<<"The areas of the first and second circles are equal" << std::endl;
    }
    system("pause");
    return 0;
}
Comments