I am writing a simple program for a class. For this particular lab assignment, I am supposed to create: "(beangame) Create a program to estimate the number of jelly beans in a jar. Assume the jar is a cylinder. (hint you will need to ask the user for the dimensions of the jar) You may also assume the jellybeans are cylinders that measure 2 cm long by 1.5 cm diameter (or 0.75 cm radius). Use the formula below.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main()
{
float height, radius, volumeOfCylinder, jellybeans, numberOfJellyBeans;
cout<<"Jellybean Estimator"<<endl;
cout<<""<<endl;
cout<<"To estimate the number of jellybeans in your jar, please enter the height of the jar"<<endl;
cout<<""<<endl;
cin>>height;
cout<<"Now, please enter the radius of the jar"<<endl;
cout<<""<<endl;
cin>>radius;
volumeOfCyclinder = (3.14159 * height * radius * radius);
cout<<"The volume of your jar is: "<<volumeOfCylinder<<endl;
cout<<""<<endl;
jellybeans = 3.14159 * 2 * 0.75 * 0.75;
numberOfJellyBeans = volumeOfCylinder / jellybeans;
cout<<"Estimated # of Beans in Specified Jar: "<<numberOfJellyBeans<<endl;
cout<<""<<endl;
system ("pause");
return 0;
}
Everything looks good until I get to "volumeOfCylinder = ();"
The error I receive is "'volumeOfCylinder' was not declared in this scope'
just a typo :)
It means you were trying to use a variable name that didn't exist.
Edit: In case it isn't clear, look at line 17.
If a box has a volume of 100 and each object you're trying to put in the box has a volume of 24, you can stuff 4 whole objects in that box, 100 / 24 == 4
This is simplified to ignore the actual shapes/collisions, I'm sure.