Here is the updated version of my code with my progress on the entirety of the project
I can't quite get my code to work the way I want, particularly i can't tell if my switch and if statements are okay.
Can you guys help me edit it please. My errors are below as well and project guidelines are on top. I'm sorry I was trying to fix it but made it worse.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main () {
bool shapenumber;
double lengthofrectangle;
double widthofrectangle;
double perimeterofrectangle;
double areaofrectangle;
const double pi = 3.14;
double lengthofradius;
double perimeterofcircle;
double areaofcircle;
double widthofsquare;
double perimeterofsquare;
double areaofsquare;
double widthofrighttriangle;
double lengthofrighttriangle;
double hypotenuseofrighttriangle;
double perimeterofrighttriangle;
double areaofrighttriangle;
do while (shapenumber < 1 && shapenumber > 4) {
cout << "What type of shape would you like to find the area and perimeter for?" << endl;
cout << "1) Right Triangle " << endl;
cout << "2) Square " << endl;
cout << "3) Circle " << endl;
cout << "4) Rectangle " << endl;
cout << "Please enter the shape you wish to use(1-4)" << endl;
cin >> shapenumber;
if (!(shapenumber == 1 || shapenumber == 2 || shapenumber == 3 || shapenumber == 4 )) {
cout << "The value " << shapenumber << " is not a valid value, please re-enter" << endl;
} }
switch (shapenumber)
//Process for a rectangle
//Rectangle input variables
case (4)
cout << "What is the length of the rectangle in inches?" << endl;
cin >> lengthofrectangle;
cout << "What is the width of the rectangle in inches?" << endl;
cin >> widthofrectangle;
//Calculate Perimeter of Rectangle
if (lengthofrectangle > 0 && widthofrectangle > 0){
perimeterofrectangle = (2*lengthofrectangle)+ (2*widthofrectangle);
areaofrectangle = lengthofrectangle * widthofrectangle;
cout << "The perimeter of the rectangle is " << perimeterofrectangle << " inches." << endl;
cout << "The area of rectangle is " << areaofrectangle << " inches squared." << endl;
return 0;
}
do while ( lengthofrectangle < 0 || widthofrectangle < 0 ) {
cout << "The value: " << lengthofrectangle << " and/or " << widthofrectangle << " is not valid." << endl;
cout << "The length and width should be greater than zero, please re-enter." << endl;
}
//Process for a Circle
//Rectangle input variables
case (3):
cout << "What is the length of the radius in inches?" << endl;
cin >> lengthofradius;
//Calculate Perimeter of circle
if (lengthofradius > 0){
perimeterofcircle = pi * 2 * lengthofradius;
// Calculate the Area of a Circle
areaofcircle = pi * (pow(lengthofradius,2));
cout << "The perimeter of the circle is " << perimeterofcircle << " inches." << endl;
cout << "The area of rectangle is " << areaofcircle << "inches squared." << endl;
return 0;
}
do while (lengthofradius <=0) {
cout << "The value: " << lengthofradius << " inches is not valid." << endl;
cout << "The length and width should be greater than zero, please re-enter." << endl;
}
//Process for a square
//square input variables
case (2):
cout << "What is the width of the square in inches?" << endl;
cin >> widthofsquare;
//Calculate Perimeter of Rectangle
if (widthofrectangle > 0){
perimeterofsquare = 4*widthofsquare;
areaofrectangle = widthofsquare * widthofsquare;
cout << "The perimeter of the square is " << perimeterofsquare << " inches." << endl;
cout << "The area of rectangle is " << areaofsquare << " inches squared." << endl;
return 0;
}
do while (widthofsquare <= 0 ) {
cout << "The value: " << widthofsquare << " is not valid." << endl;
cout << "The width should be greater than zero, please re-enter." << endl;
}
}
//Process for a Right triangle
//Right Triangle input variables
case (1):
cout << "What is the length of one side of the right triangle in inches?" << endl;
cin >> lengthofrighttriangle;
cout << "What is the width of the rectangle in inches?" << endl;
cin >> widthofrighttriangle;
//Calculate Perimeter of Rectangle
if (lengthofrighttriangle > 0 && widthofrighttriangle > 0){
hypotenuseofrighttriangle = sqrt((pow(lengthofrighttriangle,2))+ (pow(widthofrighttriangle,2)) );
perimeterofrighttriangle = lengthofrectangle + widthofrectangle + hypotenuseofrighttriangle ;
areaofrectangle = lengthofrectangle * widthofrectangle;
cout << "The perimeter of the right triangle is " << perimeterofrighttriangle << " inches." << endl;
cout << "The area of right triangle is " << areaofrighttriangle << " inches squared." << endl;
return 0;
}
do while (lengthofrighttriangle <= 0 || widthofrighttriangle <= 0) {
cout << "The value: " << lengthofrighttriangle << " and/or " << widthofrighttriangle << " is not valid." << endl;
cout << "The length and width should be greater than zero, please re-enter." << endl;
}
|
Errors:
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
\workspace\Project 4\Project 4.cpp||In function 'int main()':|
\workspace\Project 4\Project 4.cpp|42|error: expected 'while' before '(' token|
\workspace\Project 4\Project 4.cpp|45|error: expected ';' before 'case'|
\workspace\Project 4\Project 4.cpp|45|error: case label '4' not within a switch statement|
\workspace\Project 4\Project 4.cpp|47|error: expected ':' before 'cout'|
\workspace\Project 4\Project 4.cpp|69|error: expected 'while' before '(' token|
\workspace\Project 4\Project 4.cpp|69|error: expected ';' before ':' token|
\workspace\Project 4\Project 4.cpp|69|error: expected primary-expression before ':' token|
\workspace\Project 4\Project 4.cpp|92|error: expected 'while' before '(' token|
\workspace\Project 4\Project 4.cpp|92|error: expected ';' before ':' token|
\workspace\Project 4\Project 4.cpp|92|error: expected primary-expression before ':' token|
\workspace\Project 4\Project 4.cpp|109|error: expected 'while' before '}' token|
\workspace\Project 4\Project 4.cpp|109|error: expected '(' before '}' token|
\workspace\Project 4\Project 4.cpp|109|error: expected primary-expression before '}' token|
\workspace\Project 4\Project 4.cpp|109|error: expected ')' before '}' token|
\workspace\Project 4\Project 4.cpp|109|error: expected ';' before '}' token|
\workspace\Project 4\Project 4.cpp|113|error: expected unqualified-id before 'case'|
\workspace\Project 4\Project 4.cpp|116|error: 'cin' does not name a type|
\workspace\Project 4\Project 4.cpp|117|error: 'cout' does not name a type|
\workspace\Project 4\Project 4.cpp|118|error: 'cin' does not name a type|
\workspace\Project 4.cpp|120|error: expected unqualified-id before 'if'|
\workspace\Project 4.cpp|128|error: expected unqualified-id before 'do'|
||=== Build failed: 21 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|