Hello,
I am working on a program where the user enters the 3 dimensions of a solid (any solid) and the program calculates the volume of the figure!
I have tried it and i have a list of errors, but i can't seem to figure out how to fix them.
I was hoping that maybe someone here could give me a hand or whatever and help me out here. Below is my code, and below that is my error report!
Thanks a bunch, i sure hope someone here will be able to help me out!
Here is my program code:
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" << endl;
cout << "to pick the 3D object and I will calculate the volume of it." << endl;
cout << "Sounds pretty easy. Can you do it? Just try. The numbers" << endl;
cout << "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;
}
And my error report:
Code:
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:28: error: âendlâ was not declared in this scope
1project.cpp:37: error: âcinâ 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 you could let me know if you find it, but i iwll keep on working it out.
Thank you all for this great website and your help!!!