Need help computing the volume of a cylinder using repeated addition

Hi,

I need to write a program to compute the Volume of a Cylinder by Repeated Addition. I am not allowed to use the regular formula V=PiR^H

This is what I got so far:

double radius, hight, volume, pi = 3.14;

Scanner keyboard = new Scanner (System.in);

System.out.println("Enter the radius: ");
radius = keyboard.nextDouble ();

System.out.println("Enter the hight: ");
hight = keyboard.nextDouble ();
Can anyone assist me with this problem?

Last edited on
for loops
This is what I got so far:

double radius, hight, volume, pi = 3.14;

Scanner keyboard = new Scanner (System.in);

System.out.println("Enter the radius: ");
radius = keyboard.nextDouble ();

System.out.println("Enter the hight: ");
hight = keyboard.nextDouble ();
That's Java, not C or C++.

Were you specifically told you cannot use that formula?
Because 'repeated addition' typically means that you are expected to use a loop and addition instead of any one single multiplication.
Sorry, that is correct I can only use a LOOP with the addition.

But I can't figure how to do the loop
Volume of a cylinder is V = pi * (r^2) * h btw, not r^h. That would result in some pretty ridiculous cylinders though.

Anyways, for your problem, multiplication is basically repeated addition. And given the correct formula (do a google search of whatever you need), just break it down segment by segment.

1
2
3
4
for( int a = h; a > 1; --a ) // you'll need nested for loops 
{
    // continue
}
Topic archived. No new replies allowed.