Posted by: ujl September 23, 2014
C++ guru, plz help
Login in to Rate this Post:     0       ?        
Hi Alece, can you check where have i gone wrong?
#include
#include
using namespace std;

//Constant Declaration
const float PI = 3.14159265;


//Variable Declaration
float r;

int main()
{
string diameter;
string perimeter;
string area;
float r; //Radius of a semicircle
diameter, perimeter, area;


cout << "Input a command of either diameter, perimeter or area," << endl;
cout << "followed by a space, and float value for the radius." < cin >> r;

// ***** COMPUTATION *****
// Using nested if statements to calculate the diameter,
// perimeter, and area based on formulas provided on
// Prog1.txt

{
if ( r > 0 )

diameter = 2 * r;

perimeter = r * ( 2 + PI );

area = PI * pow(r,2) / 2;

else if ( r <= 0 )

cout << "You should have entered a positive value." << endl;
}

cout << "The diameter of a semicircle is " << diameter << endl;
cout << "The perimeter of a semicircle is " << perimeter << endl;
cout << "The area of a semicircle is " << area << endl;

return 0;
}
Read Full Discussion Thread for this article