//Author: Brandon Jackson
//Program Operation: To find Area and Perimeter
#include <iostream>
usingnamespace std;
int main()
{
int Shape = 0;
int Length = 0;
int Width = 0;
cout << "This program will find Area and Perimeter" << endl;
cout << "First, You need to pick the number of the shape" << endl;
cout << "You want the Area/Perimeter calculated of" << endl;
cout << "Then you input the Length followed by the Width" << endl;
cout << "Here are the shapes available, and the number" << endl;
cout << "you need to type to use that shape" << endl;
cout << "Square-1, Circle-2" << endl;
cout << "Pick the number of the shape you wish to use to continue" << endl;
cin >> Shape;
if(Shape == 1)
{
cout << "Input Length" << endl;
cin >> Length;
cout << "Input Width" << endl;
cin >> Width;
cout << "The Area of the Square is " << Length * Width << endl;
cout << "The Perimeter of the Square is " << 2 * Length + 2 * Width << endl;
}
elseif(Shape == 2)
{
cout << "Input Radius" << endl;
cin >> Length;
cout << "The Area of the Circle is " << 3.14 * Length * Length << endl;
cout << "The Perimeter of the Circle is " << 2 * 3.14 * Length << endl;
}
return 0;
}
~
~
~
~
Can someone put in the right direction on how I can
1. Loop the code so I can continue using it after I have already found the Area/Perimeter of a shape.(As In, I want to look at a Circle after I look at a square, and vise versa)
2. Keep the code from entering a fail state if someone enters a number that is not listed.(Like if I enter a 3, even though a 3 is not an option)
1. Wrap lines 14-41 in a do-while loop - You way want to ask the user whether to restart or end the program after line 41
2. The same for line 23 - If you want really checked input see http://www.cplusplus.com/forum/articles/6046/