Here is the code for my program:
It is supposed to ask for 3 dimensions of a solid to find the volume of the figure.
Code:
//Description: This program asks for the 3 dimensions of a solid to calculate the volume of the figure.
#include <iostream>
#include <cmath>
#include <string>
int main()
{
int menu;
double cubeside;
double basel;
double sqph;
double radi;
double cylh;
double radi2;
double coneh;
double radi3;
double edge;
double hexh;
string response;
do
{
cout << "\fWelcome to the Math Cheater 3000. All I need is for you
to pick the 3D object and I will calculate the volume of it.
Sounds pretty easy. Can you do it? Just try. The numbers
corresponds with the 3D figure." << endl;
// Pick a number on the menu
cout << "\n1. Cube \n2. Square Pyramid \n3. Cylinder \n4. Cone \n5. Sphere \n6. Hexagonal Prism" << endl;
cout << "Pick a number: ";
cin >> menu;
// Puts up an error that they need to pick a number on the menu and to do it again.
if(menu != 1 && menu != 2 && menu != 3 && menu != 4 && menu != 5 && menu != 6)
{
cout << "Pick a number on the menu: ";
cin >> menu;
}
// Each menu asks for the important formula points needed for the it to be solved.
if(menu == 1)
{
cout << "Pick side length of choosen cube: ";
cin >> cubeside;
cout << "The volume of cube is: "<< pow(cubeside,3) << endl;
}
if(menu == 2)
{
cout << "Pick base length and height." << endl;
cout << "Base length: ";
cin >> basel;
cout << "Height: ";
cin >> sqph;
cout << "The volume of square pyramid is: "<< (basel*basel)*(sqph)/3
<< endl;
}
if(menu == 3)
{
cout << "Pick radius and height of cylinder." << endl;
cout << "Radius: ";
cin >> radi;
cout << "Height: ";
cin >> cylh;
cout << "The volume of cylinder is: "<< (3.14 * pow(radi,2)) * cylh << endl;
}
if(menu == 4)
{
cout << "Pick radius and height of cone." << endl;
cout << "Radius: ";
cin >> radi2;
cout << "Height: ";
cin >> coneh;
cout << "The volume of cone is: "<< (3.14 * pow(radi2,2)) * coneh << endl;
}
if(menu == 5)
{
cout << "Pick radius of sphere." << endl;
cout << "Radius: ";
cin >> radi3;
cout << "The volume of sphere is: "<< (3.14 * pow(radi3,3)) * (4/3)<< endl;
}
if(menu == 6)
{
cout << "Pick edge length and height." << endl;
cout << "Edge length: ";
cin >> edge;
cout << "Height: ";
cin >> hexh;
cout << "The volume of the hexagonal prism is: "<< (.5*(edge * 6))*((edge/2)*(1.732))*(hexh)
<< endl;
}
// Asks if they want to do it again.
cout << "Again?: ";
cin >> response;
} while (response == "y" || response == "Y");
return 0;
}
Here is my error report:
Code:
1project.cpp:28:11: warning: missing terminating " character
1project.cpp:28: error: missing terminating " character
1project.cpp:29:23: error: invalid suffix "D" on integer constant
1project.cpp:31:25: error: invalid suffix "D" on integer constant
1project.cpp:31:35: warning: missing terminating " character
1project.cpp:31: error: missing terminating " character
1project.cpp: In function âint main()â:
1project.cpp:23: error: âstringâ was not declared in this scope
1project.cpp:23: error: expected `;' before âresponseâ
1project.cpp:28: error: âcoutâ was not declared in this scope
1project.cpp:29: error: âtoâ was not declared in this scope
1project.cpp:29: error: expected `;' before âpickâ
1project.cpp:37: error: âcinâ was not declared in this scope
1project.cpp:53: error: âendlâ was not declared in this scope
1project.cpp:57: error: âendlâ was not declared in this scope
1project.cpp:67: error: âendlâ was not declared in this scope
1project.cpp:76: error: âendlâ was not declared in this scope
1project.cpp:85: error: âendlâ was not declared in this scope
1project.cpp:92: error: âendlâ was not declared in this scope
1project.cpp:104: error: âresponseâ was not declared in this scope
1project.cpp:107: error: âresponseâ was not declared in this scope
It would be great if someone could help me out with my errors, and I am still trying to figure them out.
Thanks!