My Math Forum Confused about statement

 Computer Science Computer Science Forum

 September 23rd, 2011, 11:14 AM #1 Newbie   Joined: Sep 2011 Posts: 4 Thanks: 0 Confused about statement Well, first of all, here is my assignment: Code: Problem C: Infinite Cake (cake.c) Wedding Cakes come in many designs. One of the designs is a set of cylindrical layers. Each layer, from top to bottom has a bigger radius than the one above it. The number of people each layer feeds is based up on the area of the full top surface of the cake. In order for the cakes to look good, the sequence of radii of the different layers must follow an arithmetic sequence with a positive difference. (If you forgot what an arithmetic sequence is, please go online and look this up.) Your problem will be to figure out how many people a particular cake design can feed, based on the number of layers the cake has, the radius of the top layer cake, the radius of the bottom layer cake, and the amount of cake (described by the area of the top of the piece) that one person eats. For example, if a layer of cake has cross-sectional area 30.7 units2 and each person eats 5.3 units2 worth of cake, then 30.7/5.3 = 5.79 people can be fed. BUT, people aren’t fractional and we can’t give someone parts of cake from two different layers. Thus, in this case, we’ll say that the cake feeds 5 people and each of those five pieces is a bit bigger than necessary. To correctly solve the problem, make this calculation separately for each layer. For example, if one layer feeds 5.79 people and another layer feeds 8.66 people, together they would only feed 5 + 8 = 13 people, instead of 5.79 + 8.66 = 14.45 or 14 people. Input Specification 1. The number of layers will be a positive integer less than 100. 2. The radius of the top layer will be a positive real number less than 1000. 3. The bottom layer radius will be a positive real number at least as big as the top layer and less than 1000. (In a one layer cake, this number will be the same as the top layer radius.) 4. The amount of cake necessary for each individual will be a positive real number representing cross-sectional area less than the cross-sectional area of the top layer. Output Specification Output the total number of guests that can be fed with the given cake design: Your cake will feed X guests. where X is the number of guests in question. Output Samples A sample output of running the program is included below. Note that this sample is NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given above. Sample Run #1 How many layers will your cake have? 5 What is the radius of the top layer? 6 What is the radius of the bottom layer? 14 How much cake in cross-sectional area does each guest need? 4.5 Your cake will feed 374 guests. This is what I've coded so far: Code: #include #include int main() { const double PI = 3.141592654; int num_layers, num_guests, guests_fed; double radius_top, radius_bot, cake_needed, radius_diff; printf("How many layers will your cake have?\n"); scanf("%d", &num_layers); printf("What is the radius of the top layer?\n"); scanf("%lf", &radius_top); printf("What is the radius of the bottom layer?\n"); scanf("%lf", &radius_bot); printf("How much cake in cross-sectional area does each guest need?\n"); scanf("%lf", &cake_needed); radius_diff = (radius_bot - radius_top) / (num_layers - 1); int layer_1 = (PI * pow(radius_top, 2)) / cake_needed; if(num_layers == 1) { printf("Your cake will feed %d guests.\n", layer_1); } else { int layers_count = 1; double area_layers; for (layers_count = 1; layers_count < num_layers; layers_count++) area_layers = PI * pow(radius_top+2, 2) / cake_needed; printf("Your cake will feed %d guests.\n", guests_fed); } return 0; } What I don't understand is how to make a statement that allows me to calculate the area of each section of the cake, divide each area by the cross sectional area needed by each gusts, and then add them together to get the amount of guests it will feed... I have the rest down.
 September 23rd, 2011, 11:15 AM #2 Newbie   Joined: Sep 2011 Posts: 4 Thanks: 0 Re: Confused about statement By the way, the else statement that includes the for statement at the bottom obviously is a bunch of bologna that doesn't calculate what I need.
 September 23rd, 2011, 07:09 PM #3 Senior Member   Joined: Feb 2009 From: Adelaide, Australia Posts: 1,519 Thanks: 3 Re: Confused about statement It will go something like this: Code: RADIUS_STEP_SIZE = (RADIUS_BIG - RADIUS_SMALL) / (LAYERS - 1) RADIUS = RADIUS_BIG PEOPLE = 0 FOR EACH LAYER AREA = PI * RADIUS * RADIUS PEOPLE = PEOPLE + INT(AREA / CAKE_FOR_ONE) RADIUS = RADIUS - RADIUS_STEP_SIZE PRINT PEOPLE

 Tags confused, statement

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post cris(c) Applied Math 7 April 15th, 2012 08:07 AM Dontlookback Applied Math 9 March 26th, 2010 11:45 AM funsize999 Applied Math 0 March 24th, 2010 03:12 AM earthboy Elementary Math 4 March 2nd, 2010 09:53 AM momo Number Theory 4 May 29th, 2009 12:20 PM

 Contact - Home - Forums - Cryptocurrency Forum - Top