Benjamin's profileProgrammer's JournalPhotosBlogListsMore ![]() | Help |
Programmer's JournalPossibility and impossibility are only states of mind. |
||||||
|
Jellybean 1.0Language: 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:
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[]) printf("What is the length of the bean? "); beans = int(((pi * (radius * radius)) * height) * bean); printf("%s","\n\n\nThe estimated number of jellybeans is: "); In case you're wondering, the grand prize was a bag of jellybeans.
Technorati Tags: C,C++,programming,microsoft,computer,systems,analysis,consultant,consulting,freelance,software This user currently is not registered with Windows Live QnA account. Click here to learn more and get started. This user currently is not registered with Windows Live QnA account. Click here to learn more and get started. |
|||||
|
|