C'est les choses dans ma tête.

9.1.06

Surface Area Program

I just finished writing a program in C++ that will tell you the surface area of either a circle, triangle, or rectangle/square.

Here is the source code that was used, I don't care what you do with it (I guess this makes it open source <(*.*)> [The indention is probably way off after copying it into here.]):



//
// The 'Area Finder' is a program that will find the area
// of a circle, rectangle or triangle.
//
#include
#include
#include
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
// Circle, triangle, or rectangle


char choice;
cout << "Please choose:\nPress (c) to find the area of a circle.\nPress (r) to find the area of a rectangle.\nPress (t) to find the area of a triangle.\n>>";
cin >> choice;

if (choice == 'c' || choice == 'C')
{
//Area of circle
//Ask for radius, gather
double circleRadius;
cout<<"You have chosen the area of a circle.\n";
cout<<"Please input the length of the:\nRadius>>";
cin >> circleRadius;

//Calculate circle's area
double circleSubArea;
circleSubArea = circleRadius * circleRadius;

double circleArea;
circleArea = circleSubArea * 3.14159265;

//Output circle area answer
cout<<"The circle's area is: ";
cout<< circleArea << endl;

system("PAUSE");
return 0;
}
if (choice == 't' || choice == 'T')
{
//Area of triangle
//Ask for base and height, gather
double triangleBase;
cout <<"You have chosen the area of a triangle\n";
cout <<"Please enter the:\nBase>>";
cin >> triangleBase;
double triangleHeight;
cout <<"Height>>";
cin >> triangleHeight;

//Calculate area of triangle
double triangleSubArea;
triangleSubArea = 0.5 * triangleBase;

double triangleArea;
triangleArea = triangleHeight * triangleSubArea;

//Output triangle area answer
cout <<"The area of the triangle is: ";
cout << triangleArea << endl;

system("PAUSE");
return 0;
}
if (choice == 'r' || choice == 'R')
{
//Area of rectangle
//Ask for base and height, gather
double rectangleBase;
cout <<"You have chosen the area of a rectangle\n";
cout <<"Please enter the:\nBase>>";
cin >> rectangleBase;
double rectangleHeight;
cout <<"Height>>";
cin >> rectangleHeight;

//Calculate area of rectangle
double rectangleArea;
rectangleArea = rectangleBase * rectangleHeight;

//Output rectangle area answer
cout <<"The area of the rectangle is: ";
cout << rectangleArea << endl;

system("PAUSE");
return 0;
}
else
{
cout <<"Invalid input.\nPlease make a new selection";

system("PAUSE");
return 0;
}

// wait until user is ready before terminating program
// to allow the user to see the program results
system("PAUSE");
return 0;

}



You can either compile and run the program yourself, or if you don't know how or are too lazy to do that, you can always just download the .exe here: Surface Area Finder.

Enjoy <(^_^)>

No comments:

Dessart in the Desert © 2007 by Ryan Alspaugh