donut has two circle. outer circle and inner circle. calculate shaded area of donut. outer area minus area minus area of inner circle. ask user to insert radius then calculate area.
#include <iostream>
using namespace std;
int main (){
float outerCircleRadius=0;
float innerCircleRadius=0;
//Read the radius of the outer circle
while(outerCircleRadius<=0){
cout<<"Enter the radius of the outer circle: ";
cin>>outerCircleRadius;
}
innerCircleRadius=outerCircleRadius+1;
//Read the radius of the inner circle
while(innerCircleRadius<=0 || innerCircleRadius>=outerCircleRadius){
cout<<"Enter the radius of the inner circle: ";
cin>>innerCircleRadius;
}
//Calculate the area of the outer circle
float areaOuterCircle=3.14*outerCircleRadius*outerCircleRadius;
//Calculate the area of the inner circle
float areaInnerCircleRadius=3.14*innerCircleRadius*innerCircleRadius;
//calculate shaded area of donut. outer area minus area minus area of inner circle.
float donutArea=areaOuterCircle-areaInnerCircleRadius;
cout<<"Shaded area of donut: "<<donutArea<<"\n\n";
system("pause");
return 0;
}
Comments
Leave a comment