Answer to Question #294803 in C++ for Danny

Question #294803

a program that will determine the area of the following: circle, square, rectangle and triangle.


1
Expert's answer
2022-02-07T12:50:25-0500
#include <iostream>
using namespace std;


int main() {
	


	const double PI = 3.1416;
	double radius,side,side1,side2,base,height;
	double area;
	int ch=-1;




	while(ch!=5){
		cout<<"1. Calculate the area of square\n";
		cout<<"2. Calculate the area of circle\n";
		cout<<"3. Calculate the area of rectangle\n";
		cout<<"4. Calculate the area of triangle\n";
		cout<<"5. Exit\n";
		cout<<"Your choice: ";
		cin>>ch;


		switch(ch){
		case 1:
			{
				cout<<"Enter a side of a square: ";
				cin>>side;
				area = side * side;
				cout<<"The area of a square: "<<area;
			}
			break;
		case 2:
			{
				cout<<"Enter a radius of a circle: ";
				cin>>radius;
				area = PI * radius * radius;
				cout<<"The area of a circle: "<<area;
			}
			break;
		case 3:
			{
				cout<<"Enter a side 1 of a rectangle: ";
				cin>>side1;
				cout<<"Enter a side 2 of a rectangle: ";
				cin>>side2;
				area = side1 * side2;
				cout<<"The area of a rectangle: "<<area;
			}
			break;
		case 4:
			{
				cout<<"Enter a base of a triangle: ";
				cin>>base;
				cout<<"Enter a height of a triangle: ";
				cin>>height;
				area = 0.5*base * height;
				cout<<"The area of a triangle: "<<area;
			}
			break;
		case 5:
			//exit
			break;
		default:
			cout<<"Invalid Input\n";
			break;
		}
		cout<<"\n\n";
	}






	cin>>radius;
	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