Question

Write a C++ program to compute the total volume of N cones, where N is a...

Write a C++ program to compute the total volume of N cones, where N is a number entered by the user. Repeat the request for N until the user enters a positive number.

For each cone, ask for the radius and height, compute the volume, and add that volume to the total. Each time you ask the user to enter either the height or the radius, if the user does not enter a positive number, display an error message and ask them again until they enter a positive number. (If either dimension is not positive, then do not compute the volume and do not count that as one of the N cones. Allow the user to enter positive dimensions for N cones.) Display the final total volume (and do not display the cumulative total after each cone).

The volume of a cone is: v = (1/3)PI*r^2*h

where ...
v = volume (in cubic inches)
r = radius (in inches)
h = height (in inches)
PI (use 3.14159)

Program:

Follow proper coding standards. (For simplicity of the assignment, you may assume that the user enters a number and not a letter, and an integer for the number of cones.)

Start early and get the program working one piece at a time. For example, start by getting the result for one cone. Then compute the result for multiple cones. Then add the code to check for invalid inputs.

One more implementation requirement: write a subprogram to compute the volume of one cone.

Turn in your well documented source code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include<iostream>
using namespace std;
int main(){
   int n,i;
   cout<<"Enter the number of cones:";
   cin>>n;
   while(1){
       if(n<0){
           cout<<"invalid,not be negative"<<endl;
           cout<<"Enter the number of cones:";
           cin>>n;
       }
       if(n>=0){
           break;
       }
   }
   float radius,height,pi=3.14159,total=0,vol;
   for(i=0;i<n;i++){
       cout<<"Enter height of cone"<<i+1<<" in inches:";
       cin>>height;
       while(1){
           if(height<=0){
               cout<<"invalid,height be greater than 0"<<endl;
               cout<<"Enter the height of cone"<<i+1<<" in inches:";
               cin>>height;
           }
           if(height>0){
               break;
           }
       }
       cout<<"Enter radius of cone"<<i+1<<" in inches:";
       cin>>radius;
       while(1){
           if(radius<=0){
               cout<<"invalid,radius be greater than 0"<<endl;
               cout<<"Enter the radius of cone"<<i+1<<" in inches:";
               cin>>height;
           }
           if(radius>0){
               break;
           }
       }
       vol=pi*radius*radius*height;
       vol=vol/3;
       total=total+vol;
   }
   cout<<"Total volume is "<<total<<" cubic inches"<<endl;
  
}

Output:

Add a comment
Know the answer?
Add Answer to:
Write a C++ program to compute the total volume of N cones, where N is a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java only please Write a program that displays the following menu: Geometry Calculator 1.       Calculate the...

    Java only please Write a program that displays the following menu: Geometry Calculator 1.       Calculate the Area of a Circle 2.       Calculate the Area of a Triangle 3.     Calculate the Area of a Rectangle 4.       Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the formula:      area = ∏r2    Use 3.14159 for ∏. If the user enters 2 the program should ask for...

  • Geometric calclator use python to do this program. Write a program that displays the following menu:...

    Geometric calclator use python to do this program. Write a program that displays the following menu: 1. Calculate the area of circle 2. calculate the area of rectangle 3. calculate the area of triangle 4. Quit Enter your choice (1-4). if the user enters 1, your program should ask for the radius of the circle and then display its area. Use the formula to calculate the circle's area: Area = pi*r^2 Use 3.14149 for Pi and the radius of the...

  • (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator...

    (PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1 - 4): If the user enters 1, the program should ask for the radius of the circle and then display its area. If the user enters 2, the program should ask for the length and width of...

  • Write a program that receives a positive integer n from the user and then calculates the...

    Write a program that receives a positive integer n from the user and then calculates the sum below by using a loop. Your program needs to ask the user to re-enter a different number if the user enters a non-positive one. Display the result. 1 SUM 1 2 3 ... n x x n = = = + + + +

  • write a c programming Write a program that will calculate the perimeter, area and volume of...

    write a c programming Write a program that will calculate the perimeter, area and volume of a is is entered by the user. Your program will display the radius, perimeter, area and volume to the monitor and will also save them to a file called "circlePAV.txt". Your program should prompt the user for the radius until the user enters -1. Use the following structure. typedef struct ( float radius; float area, float perimeter; float volume; ylinder Figure>

  • Write MIPS code, please. Following: Write a program to be used by the Wisconsin DNR to...

    Write MIPS code, please. Following: Write a program to be used by the Wisconsin DNR to track the number of Deer Hunting Licenses issued in a county and the state. It will display a menu with 5 choices numbered 1-5. They are (1) update the count, (2) display the number of licenses already issued to a county whose number is input, (3) display the county number and the number of licenses already issued to a range of counties whose starting...

  • PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program...

    PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program in which the statements are in the incorrect order. Rearrange the statements in the following order so that the program prompts the user to input: The height of the base of a cylinder The radius of the base of a cylinder The program then outputs (in order): The volume of the cylinder. The surface area of the cylinder Format the output to two decimal...

  • (The file should have your program and the console input/output of your program) 3.18: Pizza Pi...

    (The file should have your program and the console input/output of your program) 3.18: Pizza Pi Joe’s Pizza Palace needs a program to calculate the number of slices a pizza of any size can be divided into. The program should perform the following steps: Ask the user for the diameter of the pizza in inches. Calculate the number of slices that may be taken from a pizza of that size. Display a message telling the number of slices. To calculate...

  • Need in C++ Assignment #1: Write a program to ask the user for a sphere radius...

    Need in C++ Assignment #1: Write a program to ask the user for a sphere radius r as a double. Then compute and display the sphere surface area using S-4*PI'r*r as double. Then compute and display the sphere volume using V-(1.33)*PIr'r*r as double. Use: const double PI-3.14;

  • Write a C program named assignment04.cpp that will ask for and read in a float for...

    Write a C program named assignment04.cpp that will ask for and read in a float for a radius ask for and read in a float for the height each of the following functions will calculate some property of a shape (area, volume, circumference, etc) The functions will accept one or two parameters (radius and/or height) and return the proper calculation. There is no input/output (cin or cout) in the function – just the calculation write the following functions float areaCircle(float...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT