I'm trying to create this code that when you choose triangle it will choose n=3 that then will be able to be included in the interior angles sum formula. is that possible? this is for school it's for the question below;
(n−2)(180 degrees)where n is the number of sides.
Write a program that prompts the user to enter one of the following triangle
square
pentagon
hexagon
Use the input to define the value of n via a switch/case structure; then use n to calculate the sum of the interior angles in the figure.
This is the code I have
clear, clcshapes = input('Choose one', 'Triangle', 'Square', 'Pentagon', 'Hexagon')switch shapes case 3 Triangle = 3 n = Triangle sum = (n-2)*(180) table = [n; sum] fprintf('n = %g sum of all interior angles is %g degrees \n', table) case 4 n = 4 sum = (n-2)*(180) table = [n; sum] fprintf('n = %g sum of all interior angles is %g degrees \n', table) case 5 n = 5 sum = (n-2)*(180) table = [n; sum] fprintf('n = %g sum of all interior angles is %g degrees \n', table) case 6 n = 6 sum = (n-2)*(180) table = [n; sum] fprintf('n = %g sum of all interior angles is %g degrees \n', table)end
Best Answer