Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How can I write a code in c+using switch,to find the area,the perimeter of triangle,circle and square all in one?

+1 vote
asked Nov 14, 2019 by Klaudia Dogani (130 points)

3 Answers

0 votes
answered Nov 15, 2019 by Artem (330 points)
What do you need finally? Which data do you have?
0 votes
answered Nov 15, 2019 by gameforcer (2,990 points)
Create a switch depending on the type of figure of which area you want to calculate. Then in the corresponding switch case prompt user to input required data and then calculate the area and/or perimeter from it.
0 votes
answered Nov 16, 2019 by anonymous

With my experiences with C++(I'm a new), I will recommend you to create distinct functions and classes, then execute it in main (you can use switch there).

#include <cmath>

double findCircleArea(double radius) {

    /* You can add more decimals to get more exactly */

    /* pow(double, double) is used for calculating squares */

    double circleArea = pow(radius, 2) * 3.14159265; 

    return circleArea;


double findSquareArea(double side) {

    double squareArea = pow(side, 2);

    return squareArea;


double findTriangleArea(double side) {

    double triangleArea = pow(side, 2) / 2;

    return triangleArea;


And for the perĂ­metres you do the same. And then execute them on main function.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.