Question
This C++ program is supposed to use the switch statement that I have written to take user input on the type of star shape that
This C++ program is supposed to use the switch statement that I have written to take user input on the type of star shape that they want to analyze and then it is supposed to prompt the user to input the required data. When the program runs correctly it is supposed to output various data on the shape that they have selected. As of right now I have compiled the program and have not received any error messages but when I select the statement that I want to analyze it outputs zero's for all the values and doesn't prompt me a second time to input the required information to calculate the outputs. Because I'm fairly new to C++ programming I'm having trouble finding my error. If you would look over my code and point out my errors I would greatly appreciate it.
Thank you for your help,
#include
using namespace std;
int main() { double diameter = 0.0; double heightLong = 0.0; double heightShort = 0.0; double perimeter = 0.0; double lengthLong = 0.0; double lengthShort = 0.0; double baseLength = 0.0; double area = 0.0; double edgeLength = 0.0; double outerAngle = 0.0; double innerAngle = 0.0; double height = 0.0; double const PI = 3.1415926535898; int num = 0; int points = 0; double spikeBase = 0.0; double spikeHeight = 0.0; double chordLength = 0.0; char doubleStarPolygon; char threeStarPolygon; char polygramPolygon;
(doubleStarPolygon == 'D' || doubleStarPolygon == 'd' || doubleStarPolygon == 2); (threeStarPolygon == 'T' || threeStarPolygon == 't' || threeStarPolygon == 3); (polygramPolygon == 'P' || polygramPolygon == 'p' || polygramPolygon == 4);
cout<< "Double star polygon = d = D = 2" < cout<< "Your selection: " < switch (num) { case 0: case 1: case 2: cout<< "Double star polygon calculator" < cout<< "Length long valid range [1.00 < Length long < 236.00]" < (1.00 cout<< "Base length valid range [1.00 < Base length < 29.5]" < (1.00 cout<< "Enter value for Base Length: " < heightLong = sqrt(pow (lengthLong,2) - (pow (baseLength,2) /4)); cout<< "Height Long= " << heightLong < heightShort = sqrt(pow (lengthShort,2) - (pow (baseLength,2) /4)); cout<< "Height Short= " << heightShort < diameter = 2 * heightLong + (baseLength * (1 + sqrt(2))); cout<< "Diameter= " << diameter < perimeter = 8 * (lengthShort + lengthLong); cout<< "Perimeter= " << perimeter < area = 2 * baseLength * (baseLength * (1 + sqrt(2)) + (heightLong + heightShort)); cout<< "Area= " << area < break; case 3: cout<< "Three star polygon calculator" < (0 cout<< "Inner angle valid range [0 < Inner angle < 60]" < cout<< "Enter value for Inner angle: " < (1 cout<< "Edge length valid range [1 < Edge length < 132]" < cout<< "Enter value for Edge length: " < outerAngle = 120 + innerAngle; cout<< "Outer angle= " << outerAngle < cout<< "Spike base= " << spikeBase < spikeHeight = sqrt((4 * pow(edgeLength,2) - pow(spikeBase,2)) / 4); cout<< "Spike height= " << spikeHeight < chordLength = sqrt(2 * pow(edgeLength,2) * (1 - cos(outerAngle))); cout<< "Chord length= " << chordLength < height = (sqrt(3) / 2) * chordLength; cout<< "Height= " << height < perimeter = 6 * edgeLength; cout<< "Perimeter= " << perimeter < area = (3/2) * spikeHeight * spikeBase + (sqrt(3)/4) * pow(spikeBase,2); cout<< "Area= " << area < break; case 4: cout<< "Polygram calculator" < (3 cout<< "Number of points valid range [3 < Number of points < 100]" < cout<< "Enter number of points: " < (1 cout<< "Edge length valid range [1 < Edge length < 132]" < cout<< "Enter value for edge length: " < (0 innerAngle = (outerAngle - 360) / points; cout<< "Inner angle= " << innerAngle < baseLength = sqrt(2 * pow(edgeLength,2) * (1 - cos(innerAngle))); cout<< "Base length= " << baseLength < outerAngle = 360 / (points + edgeLength); cout<< "Outer angle= " << outerAngle < spikeHeight = sqrt((4 * pow(edgeLength,2) - pow(baseLength,2)) / 4); cout<< "Spike height= " << spikeHeight < chordLength = sqrt(2 * pow(edgeLength,2) * (1 - cos(outerAngle))); cout<< "Chord length= " << chordLength < perimeter = 2 * points * edgeLength; cout<< "Perimeter= " << perimeter < area = (points * pow(baseLength,2)) / (4 * tan(PI / points)) + points * spikeHeight * (baseLength / 2); break; } return 0; cout<< "Enter number of points: " < (1 cout<< "Edge length valid range [1 < Edge length < 132]" < cout<< "Enter value for edge length: " < (0 cout<< "Outer angle valid range [0 < Outer angle < 60]" < cout<< "Enter value for outer angle: " < innerAngle = (outerAngle - 360) / points; cout<< "Inner angle= " << innerAngle < cout<< "Base length= " << baseLength < outerAngle = 360 / (points + edgeLength); cout<< "Outer angle= " << outerAngle < spikeHeight = sqrt((4 * pow(edgeLength,2) - pow(baseLength,2)) / 4); cout<< "Spike height= " << spikeHeight < chordLength = sqrt(2 * pow(edgeLength,2) * (1 - cos(outerAngle))); cout<< "Chord length= " << chordLength < perimeter = 2 * points * edgeLength; cout<< "Perimeter= " << perimeter < area = (points * pow(baseLength,2)) / (4 * tan(PI / points)) + points * spikeHeight * (baseLength / 2); break; } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started