Alright well this is supposed to be a basic Geometry calculator that uses set formulas to identify the "chosen" property of the figure by just pluggin in #'s that are used in that formula.
I have to admit I'm not expirienced at all in C++ and probably made a ton of mistakes (my compiler agrees). I checked the code and it seems like for all operators that I input that are more than 2 digits that my compiler gives me a "multi-character character constant" error. I also have an = # of "comparison" errors meaning there is something that I am doing wrong every single time.
For one, I'm not even sure if your allowed to use parenthesis in C++ coding, and if so how do I implement them? Say we have the formula for the Volume of a sphere (4/3 pie Radius(cubed)) How do I implement that. Since you can't insert fractions (can you) how would I put them in, as decimals? If I put them in my compiler gives me an error, does this mean I need to give my declared variables a special characteristic (ie: short, long ect.)?
Thanks for your help guys, please don't just edit my code, also explain why if you could so I don't make the same mistake next time.
#include <iostream>
using namespace std;
int main()
{
float area;
float base;
float Sbase; //Small Base (Trapezoid Formula)
float Bbase; // Big Base (Trapezoid Formula)
float Wbase; //Width of Base (Pyramid Formula)
float Lbase; //Length of Base (Pyramid Formula)
float circumference;
float height;
float length;
float perimeter;
float radius;
float side;
float sidea;
float sideb;
float width;
char op;
char again = 'y';
cout <<"\n Welcome to the Version 0.2 calculator by Niklas Kunkel";
cout <<" " <<endl;
cout <<" " <<endl;
cout <<"\n Here is a list of all current functions."<<endl;
cout <<"Each funton will have an = sign and a number."<<endl;
cout <<"Enter the number to use that function and then press enter"<<endl;
cout <<"\n " <<endl;
cout <<"\n "<<endl;
while (again == 'y')
{
//here the user chooses what he wants to find out
cout <<"FUNCTION LIST"<<endl;
cout <<""<<endl;
cout <<"\nArea of a Square = 1"<<endl;
cout <<"Perimter of a Square = 2"<<endl;
cout <<"Length of a side of a square = 3"<<endl;
cout <<"\nArea of a Rectangle = 4"<<endl;
cout <<"Perimeter of a Rectangle = 5"<<endl;
cout <<"\nArea of a Circle = 6"<<endl;
cout <<"Radius of a Circle = 7"<<endl;
cout <<"Circumference of a Cirlce = 8"<<endl;
cout <<"\nArea of a Parallelogram = 9"<<endl;
cout <<"Perimeter of a Parallelogram = 10"<<endl;
cout <<"\nArea of a Trapezoid = 11"<<endl;
cout <<"\nVolume of a Cylinder = 12"<<endl;
cout <<"Lateral Surface Area of a Cylinder = 13"<<endl;
cout <<"\nVolume of a Cone = 14"<<endl;
cout <<"Later Surface Area of a Cone = 15"<<endl;
cout <<"\nVolume of a Pyramid = 16"<<endl;
cout <<"\nVolume of a Rectangular Solid (3d) = 17"<<endl;
cout <<"Area of a Rectangular Solid (3d) = 18" <<endl;
cout <<"\nVolume of a Sphere = 19"<<endl;
cout <<"Surface Area of a Sphere = 20"<<endl;
cin >> op;
if (op == '1')
{
cout <<"\nPlease enter the length of any side of the Square"<<endl;
cin >> side;
cout <<"\n Area of the Square = " << side * side <<endl;
}
if (op == '2')
{
cout <<"\n Please enter the length of any side of the Square"<<endl;
cin >> side;
cout <<"\n Perimtere of the Square = " << side + side + side + side <<endl;
}
if (op == '3')
{
cout <<"\n Please enter the area of the square"<<endl;
cin >> area;
cout <<"\n Length of the side of the square = " << area / 4 <<endl;
}
if (op == '4')
{
cout <<" \nPlease enter the Length of the Rectangle"<<endl;
cin >> length;
cout <<"PLease enter the Width of the Rectangle"<<endl;
cin >> width;
cout <<"Area of the Rectangle = " << length * width <<endl;
}
if (op == '5')
{
cout <<" \nPlease enter the Length of the Rectangle"<<endl;
cin >> length;
cout <<"Please enter the Width of the Rectangle"<<endl;
cin >> width;
cout <<"Perimeter of the Rectangle = " << length + length + width + width<<endl;
}
if (op == '6')
{
cout <<"\nPlease enter the radius of the Circle"<<endl;
cin >> radius;
cout <<"\nArea of the Circle = " << radius * radius * 3.14<<endl;
}
if (op == '7')
{
cout <<"\nPlease enter the Area of the Circle"<<endl;
cin >>area;
cout <<"Radius of the Circle = " << area / 3.14<<endl;
}
if (op == '8')
{
cout <<"\nPlease enter the Radius of the Cirlce"<<endl;
cin >> radius;
cout <<"Circumference of the Circle = " << radius * 2 * 3.14<<endl;
}
if (op == '9')
{
cout <<"\nPlease enter the Base of the Parallelogram"<<endl;
cin >> base;
cout <<"Please enter the Height of the Parallelogram"<<endl;
cin >> height;
cout <<"Area of the Paralleogram = " << base * height<<endl;
}
if (op == '10')
{
cout <<"\nPlease enter the length of one side of the Parallelogram"<<endl;
cin >> sidea;
cout <<"Please enter the length of another side of the Paralellogram that is not parallel to the first"<<endl;
cin >> sideb;
cout <<"Perimete of the Paralleogram = " << sidea + sidea + sideb + sideb <<endl;
}
if (op == '11')
{
cout <<"\n Please enter the Height"<< endl;
cin >> height;
cout <<"Please enter the length of the smaller base"<<endl;
cin >> sidea;
cout <<"Please enter the length of the larger base"<<endl;
cin >> sideb;
cout <<"The Area of the Trapezoid = " << .5 * height * (sidea + sideb) <<endl;
}
if (op == '12')
{
cout <<"\nPlease enter the radius of the cylinder"<<endl;
cin >> radius;
cout <<"Please enter the height of the cylinder"<<endl;
cin >> height;
cout <<"Volume of the Cylinder = " << radius * radius * height * 3.14 <<endl;
}
if (op == '13')
{
cout <<"\nPlease enter the radius of the cylinder"<< endl;
cin >> radius;
cout <<"Please enter the height of the cylinder"<<endl;
cin >> height;
cout <<" Lateral Surface Area of the Cylinder = " << 2 * 3.14 * radius * height <<endl;
}
if (op == '14')
{
cout <<"\nPlease enter the radius of the cylinder"<<endl;
cin >> radius;
cout <<"Please enter the height of the cylinder"<<endl;
cin >> height;
cout <<"Volume of the Cone = " .3 * 3.14 * radius * radius * height <<endl;
}
if (op == '15')
{
cout <<"\nPlease enter the height" <<endl;
cin >> height;
cout <<"Please enter the radius" <<endl;
cin >> radius;
cout <<"Later Surface Area of the Cone = " << (radius * radius) + (height * height) <<endl;
}
if (op == '16')
{
cout <<"\nPlease enter the length of the pyramid" <<endl;
cin >> length;
cout <<"Please enter the the height of the pyramid" <<endl;
cin >> height;
cout <<"Please enter the width of the pyramid" <<endl;
cin >> width;
cout <<\n"Volume of the Pyramid = " << .33(length * width * height) <<endl;
}
if (op == '17')
{
cout <<"\nPlease enter the length of the Rectangular Solid" <<endl;
cin >> length;
cout <<"Please enter the the height of the Rectangular Solid" <<endl;
cin >> height;
cout <<"Please enter the width of the Rectangular Solid" <<endl;
cin >> width;
cout <<"\nVolume of the Rectangular Solid = " << length * width * height <<endl;
}
if (op == '18')
{
cout <<"\nPlease enter the length of the Rectangular Solid" <<endl;
cin >> length;
cout <<"Please enter the the height of the Rectangular Solid" <<endl;
cin >> height;
cout <<"Please enter the width of the Rectangular Solid" <<endl;
cin >> width;
cout <<"\nArea of the Rectangular Solid = " << 2(length * width) + 2(length * height) + 2(width * height) <<endl;
}
if (op == '19')
{
cout <<"\nPlease enter the radius" <<endl;
cin >> radius;
cout <<"\nVolume of the Sphere = " << radius * radius * radius * 3.14 * 1.33 <<endl;
}
if (op == '20')
{
cout <<"\nPlease enter the radius" <<endl;
cin >> radius;
cout <<"\nSurface Area of the Sphere = " << radius * radius * 4 * 3.14 <<endl;
}
else
cout << "\n Invalid Operation";
cout << "\n Do you want to try again? (y/n): ";
cin >> again;
}
return 0;
}