
Computer Science Computer Science Forum 
 LinkBack  Thread Tools  Display Modes 
September 23rd, 2011, 12:14 PM  #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 crosssectional 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 crosssectional area less than the crosssectional 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 crosssectional area does each guest need? 4.5 Your cake will feed 374 guests. Code: #include <stdio.h> #include <math.h> 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 crosssectional 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; } 
September 23rd, 2011, 12:15 PM  #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, 08: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  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
contradicting a statement  cris(c)  Applied Math  7  April 15th, 2012 09:07 AM 
Logic statement  Dontlookback  Applied Math  9  March 26th, 2010 12:45 PM 
Negate a statement  funsize999  Applied Math  0  March 24th, 2010 04:12 AM 
prove a statement  earthboy  Elementary Math  4  March 2nd, 2010 10:53 AM 
Both prime : statement  momo  Number Theory  4  May 29th, 2009 01:20 PM 