Menu using switch
Source Code
|
|
Run Output
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.
Created: 1-Mar-2026 16:57 | Updated: 1-Mar-2026 17:16|
