Benjamin's profileProgrammer's JournalPhotosBlogListsMore Tools Help

Programmer's Journal

Possibility and impossibility are only states of mind.

Benjamin Howard

Occupation
Location
Interests
Originally from Atlanta, Ga. Been programming for almost 20 years.
Thanks for visiting!
Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.
Public folders

Jellybean 1.0

Language:  C++

A few years back, I was at the grocery store doing some shopping and after I checked out my groceries one of the employees asked me to participate in a jellybean contest where you have to guess how many jellybeans in a jar.  So I said sure thing however, I took a different approach.

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:

  1. Measure a single jellybean lengthwise; use that as your base of measurement (i.e. centimeter or inch)
  2. Measure the diameter of the jar's base
  3. Measure the jar's height
  4. Calculate the radius by dividing the diameter in half
  5. Calculate the area and multiply that by the height of the jar to get the capacity
  6. Factor in the jellybean's measurement with the capacity of the jar

This is under the assumption that the jar is cylinder shaped, if it were shaped like a rectangular prism the whole thing would be much easier, just take the width times the depth times the height of the jar.  If by any chance the jar is oval shaped, then you can not use the base to get the diameter.  You'll have to get it at the jar's widest point, calculate the estimate based on its circumference, then make a substantial subtraction.  So this program can be modified to serve as a PDA utility so that the next time you're ever given to opportunity to win a jellybean contest, just take the necessary measurements and plug in the numbers into this program and it will estimate for you.

#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.

 

Questions I've Asked

This user currently is not registered with Windows Live QnA account. Click here to learn more and get started.

Questions I've Answered

This user currently is not registered with Windows Live QnA account. Click here to learn more and get started.