Menu using switch – CSKC
Sign In

Search

Code Learning #CPP#7618    siteicon   siteicon  

Menu using switch

Source Code

TC++ #7618

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

Code Understanding

This program allows the user to calculate different properties of a square based on their choice using a switch statement.
β€’ float s; int c=0;
o s stores the side of the square.
o c stores the menu choice.
β€’ cin >> s; takes the side length from the user.
β€’ The program displays a menu:
1. Find Area
2. Find Perimeter
3. Find Diagonal
4. Exit
β€’ cin >> c; takes the user’s choice.
β€’ switch(c) executes the corresponding calculation:
o 1 β†’ Area = s * s
o 2 β†’ Perimeter = 4 * s
o 3 β†’ Diagonal = s * sqrt(2) (using cmath library)
o 4 β†’ exit(0) ends the program
o default handles wrong input.


Share

Created: 1-Mar-2026 16:57 | Updated: 1-Mar-2026 17:16|