Answer to Question #187707 in C++ for deeba

Question #187707

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.



1
Expert's answer
2021-05-01T08:17:21-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS