I decided not to guess how many jellybeans were in the jar, that would be a waste of time. So my friend and I took out a tape measure, a pad and pen and took down the information that we did know to calculate the estimate using basic geometry. A few weeks later I got a call from the store telling me I won, that I was off by sixteen jellybeans.
So, here is what I did:
- Measure a single jellybean lengthwise; use that as your base of measurement (i.e. centimeter or inch)
- Measure the diameter of the jar’s base
- Measure the jar’s height
- Calculate the radius by dividing the diameter in half
- Calculate the area and multiply that by the height of the jar to get the capacity
- Factor in the jellybean’s measurement with the capacity of the jar
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
double pi = 3.1415927;
float radius, height, bean;
int beans;
printf("What is the length of the bean? ");
scanf_s("%u",&bean);
printf("What is the radius of the jar’s base? ");
scanf_s("%u",&radius);
printf("What is the height of the jar? ");
scanf_s("%u",&height);
beans = int(((pi * (radius * radius)) * height) * bean);
printf("%s","\n\n\nThe estimated number of jellybeans is: ");
printf("$i",beans);
getchar();
}
In case you’re wondering, the grand prize was a bag of jellybeans.

No comments:
Post a Comment