Lab Assignment - Jellybean Jar - Not declared in this scope

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.

VolumeOfCylinder = 3.14159 * height * radius * radius"

This is what I have come up with so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cstdlib>
using namespace 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'

What did I do wrong?
Last edited on
1
2
volumeOfCylinder
volumeOfCyclinder

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.
Last edited on
Wow, I can't believe I did that. Thanks for pointing that out...
Topic archived. No new replies allowed.