Write a C program to output the area of a rectangle circle
Write a C ++ program to output the area of a rectangle, circle, and triangle. Ask the user which is desired, ask the parameters needed to compute the results. Allow the user to continue inputting requests until he/she tells the program to stop.
Solution
// C++ code
#include <iostream>
 #include <fstream>
 #include <string>
 #include <cassert>
 #include <iomanip> // std::setprecision
 #include <math.h>
using namespace std;
# define M_PI 3.14159265358979323846 /* pi */
 int main ()
 {
    char shape;
    char again;
    double radius, length, breadth, base, height;
   while(true)
    {
        cout << \"What shape Would you like the area for? (r-rectangle; t-traingle; c-circle) \";
        cin >> shape;
       if(shape == \'r\')
        {
            cout << \"What is the length of your rectangle? \";
            cin >> length;
            cout << \"What is the breadth of your rectangle? \";
            cin >> breadth;
           cout << \"The area of your rectangle is \" << (length*breadth) << \" square units\ \";
        }
       else if(shape == \'t\')
        {
            cout << \"What is the base of your traingle? \";
            cin >> base;
            cout << \"What is the height of your traingle? \";
            cin >> height;
           cout << \"The area of your traingle is \" << (0.5*base*height) << \" square units\ \";
        }
       else if(shape == \'c\')
        {
            cout << \"What is the radius of your circle? \";
            cin >> radius;
           cout << \"The area of your circle is \" << (M_PI*radius*radius) << \" square units\ \";
        }
       else
        {
            cout << \"Invalid input\ \";
        }
        cout << \"\ Would you like t input another shape(y or n) \";
        cin >> again;
       if(again == \'n\')
            break;
    }
 return 0;
 }
/*
 output:
What shape Would you like the area for? (r-rectangle; t-traingle; c-circle) t
 What is the base of your traingle? 12
 What is the height of your traingle? 7
 The area of your traingle is 42 square units
Would you like t input another shape(y or n) y
 What shape Would you like the area for? (r-rectangle; t-traingle; c-circle) c
 What is the radius of your circle? 5.5
 The area of your circle is 95.0332 square units
Would you like t input another shape(y or n) y
 What shape Would you like the area for? (r-rectangle; t-traingle; c-circle) r
 What is the length of your rectangle? 3
 What is the breadth of your rectangle? 4
 The area of your rectangle is 12 square units
Would you like t input another shape(y or n) n
 */


