Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #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: " <>num;

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>lengthShort;

cout<< "Base length valid range [1.00 < Base length < 29.5]" <

(1.00

cout<< "Enter value for Base Length: " <>baseLength;

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: " <>innerAngle;

(1

cout<< "Edge length valid range [1 < Edge length < 132]" <

cout<< "Enter value for Edge length: " <>edgeLength;

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: " <>points;

(1

cout<< "Edge length valid range [1 < Edge length < 132]" <

cout<< "Enter value for edge length: " <>edgeLength;

(0>outerAngle;

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: " <>points;

(1

cout<< "Edge length valid range [1 < Edge length < 132]" <

cout<< "Enter value for edge length: " <>edgeLength;

(0

cout<< "Outer angle valid range [0 < Outer angle < 60]" <

cout<< "Enter value for outer angle: " <>outerAngle;

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

Describe a persuasive message.

Answered: 1 week ago

Question

Identify and use the five steps for conducting research.

Answered: 1 week ago

Question

List the goals of a persuasive message.

Answered: 1 week ago