My Computer Forum Computer Science Forum

Go Back   My Computer Forum > Computer Science Forum > Programming

Programming Programming Languages, Interpreters, and Compilers - Assembly, Declarative, Machine, Object Oriented, Iterative

LinkBack Thread Tools Display Modes
September 23rd, 2011, 12:26 PM   #1
Joined: Sep 2011
Posts: 1
Creating a statement...

Alright here's the problem:
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 arent
fractional and we cant give someone parts of cake from two different layers. Thus, in
this case, well 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
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?
What is the radius of the top layer?
What is the radius of the bottom layer?
How much cake in cross-sectional area does each guest need?
Your cake will feed 374 guests.
Here's what I have so far. **ignore some of the bad formatting, I copied it in weird**

#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 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);     

          int layers_count = 1;         
          double area_layers;         
          while(layers_count < num_layers)         
                  layers_count = layers_count++;        

return 0; 
My next step would be to make some sort of statement that calculates the areas of each section of the cake and divides them each by the cross sectional area of caked needed for each person. When all of these are added up, along with layer 1, it gives the total amount of people the cake will feed. I get the logic behind it, but I don't know how to make a statement that performs this. Can anyone help me out here?
shukiren is offline  

My Computer Forum is free to register and we welcome everyone!

November 25th, 2011, 12:37 PM   #2
Posts: n/a
Re: Creating a statement...

In Microsoft Professional Suite there is an Access Sample Sales Database the does what you are asking.

  My Computer Forum > Computer Science Forum > Programming

creating, statement

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Script Wrapper for SCCM jeanemedi Computer Science 0 November 5th, 2012 05:44 AM

Copyright © 2019 My Computer Forum Forum. All rights reserved.