title: trying to calculate volume of a cone
body: <p>I'm trying to approximate the volume of a cone with a MATLAB program that uses n equalheight discs(cylinders)  with decreasing radii. The biggest disc on the bottom, the next on top of it, and the one with smallest radii on the top. I have no troubles getting the inputs, but I can't figure out how to calculate the volume with using discs. For loop or while loop?</p>
  
  <p>By the way the volume of a disc is pi*r*r*h, h is height, r is radius</p>
  
  <p>Next step, i need to calculate number of disc needed so that error percentage is less than 1%</p>
  
  <p>This is all i've written so far, it works great calculating the volume with finite number of disc, but i cant figure out how to calculate the number of discs so that error percentage is less than 1%. I would appreciate the help.Thanks!!</p>
  
  <pre><code>h=input('Enter height: ');
  if (h&lt;=0)
  disp('Height must be positive!');
  else
  r=input('Enter base radius: ');
  if (r&lt;=0)
  disp('Base radius must be positive!');
  else
  n=input('Enter number of discs: ');
  ne=n;
    while n&gt;0 || n~=0
               if n&gt;0 &amp;&amp; (mod(n,1))==0
                  Vcone=(1/3)*(pi*r*r*h);
                  VTotal=0;
                    for i=n:-1:1
                        rEachDisc=r*(((i-1)*h)/n)/h;
                        VEachDisc=(pi*rEachDisc*rEachDisc)*(h/n);
                        VTotal=VTotal+VEachDisc;                   
                    end
                  Vapp=VTotal+((pi*r*r)*(h/n));
                  eror=abs((Vcone-Vapp)/Vcone*100);
                  fprintf('For n=%g, approximated volume: %g ; error:     %g%%\n',n,Vapp,eror)
               else
                  disp('This is not a positive integer!');
               end
          n=input('Enter number of discs: ');
    end 
  end
  end
  VTotal=0;
  t=1;
  Vcone=(1/3)*(pi*r*r*h);
  for i=ne:-1:1
  rEachDisc=r*(((i-1)*h)/ne)/h;
  VEachDisc=(pi*rEachDisc*rEachDisc)*(h/ne);
  VTotal=VTotal+VEachDisc; 
  Vapp=VTotal+((pi*r*r)*(h/ne));
  eror=abs((Vcone-Vapp)/Vcone*100);
  if eror==1
  fprintf('We need at least %g discs to approximate the volume with less than 1%%   error.',ne);
    break
  end
  end
  </code></pre>