Join 135,935 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,674 people online right now. Registration is fast and FREE... Join Now!
cout<<"Which shape are you working with"<<endl; cin>>'1' || '2' || '3';
if (cin == 1) {
cout<<"Please enter the radius (of ball), height, length of object & radius of rod"<<endl; cin>>radius>>height>>length>>rod; cout<<"Dumbell: "<<endl; cout<<"Radius of the ball: "<<radius<<endl; cout<<"Radius of the rod: "<<rod<<endl; cout<<"Length of rod: "<<heigth<<endl; vol = (4/3) * 3.142 * radius * radius * radius: cout<<"The volume of the dumbbell is "<<vol<<" "<<"cubic inches"<<endl; }
else if (cin == 2) { cout<<"Please enter the radius of the wheel, radius of the rod, length of the rod, width of the wheel"<<endl; cin>>radius>>rod>>length>>width; cout<<"Axle: "<<endl; cout<<"Radius of the wheel: "<<radius<<endl; cout<<"Radius of the rod: "<<rod<<endl; cout<<"Length of the rod: "<<length<<endl; cout<<"Width of the wheel: "<<width<<endl; vol = ((pie * (radius *radius) * length) * 2) cout<<"The volume of the axel is "<<vol<<" "<<"cubic inches"<<endl; }
else if (cin==3) { cout<<"Please enter the radius (of rod), the length of the rod & heigth of the cone"<<endl; cin>>radius>>length>>heigth; cout<<"Spear: "<<endl; cout<<"Radius of the rod: "<<radius<<endl; cout<<"Length of the rod: "<<length<<endl; cout<<"Height of the cone: "<<heigth<<endl; vol = (1/3 * pie * (radius * radius) * height) * 2; cout<<"The volume of the spear is "<<vol<<" "<<"cubic inches"<<endl;
return 0; }
I know it's a crazy one..but here is the assignment: Write a C++ program that calculates the volume of 3 different geometric shapes. Your program should give the user a menu like the following and repeat until the user wants to stop. Volume Calculation Program Select the Number of Your Chosen Object 1. Dumbbell 2. Axle 3. Spear When the user selects one of the 3 objects, the program should then request the appropriate measurements (in inches) and then calculate and display the volume of that object. The result should be printed showing cubic-inch units with 3 decimals of precision. Axle: 2 cylinders and a rod Dumbbell: two spheres and a rod Spears: two cones and a rod
Program requirements and Assumptions Formulas and Abbr. II P1 = 3.141 59 r radius = height (or length) Vol. of a sphere = 4I3flr3 Area of a circle = flr2 Vol. of a cylinder fl9b Vol. of a cone = 1/3fJr2h 1. The rod-end fits against the dumbbell ball snugly; there is no “air-gap’. You may assume that there is no loss of volume of the ball when the rod is fitted against it. 2. The radius of the dumbbell and axle center rods cannot be larger than half the radius of the ball or wheel. Do not make calculations if the rod radius is more than half of the ball or wheel radius. Give the user an error message instead. For example, if the user enters a radius of 5 inches for the ball or wheel, the rod radius must be no larger than 2.5 inches. 3. The spear’s cone base has exactly the same radius as the connecting rod. 4. Output is to both the monitor and the printer.
Do you do a single assignment on your own? We have helped you with like 3 already and you seem to come up with a new one every day. You are also making silly mistakes in it. Look at where you specify the length of a rod in your first group of statements, you output the height and then you even spell height wrong.
Please attempt to do a compile and weed out the simple errors and give it a whirl yourself before asking us to debug your assignments. We are not all human compilers here (well I am, but that is besides the point).
You don't even specify a question. Please read the forum rules about posting.
cout<<"Which shape are you working with"<<endl; cin>>'1' || '2' || '3';
if (cin == 1) {
cout<<"Please enter the radius (of ball), height, length of object & radius of rod"<<endl; cin>>radius>>height>>length>>rod; cout<<"Dumbell: "<<endl; cout<<"Radius of the ball: "<<radius<<endl; cout<<"Radius of the rod: "<<rod<<endl; cout<<"Length of rod: "<<heigth<<endl; vol = (4/3) * 3.142 * radius * radius * radius: cout<<"The volume of the dumbbell is "<<vol<<" "<<"cubic inches"<<endl; }
else if (cin == 2) { cout<<"Please enter the radius of the wheel, radius of the rod, length of the rod, width of the wheel"<<endl; cin>>radius>>rod>>length>>width; cout<<"Axle: "<<endl; cout<<"Radius of the wheel: "<<radius<<endl; cout<<"Radius of the rod: "<<rod<<endl; cout<<"Length of the rod: "<<length<<endl; cout<<"Width of the wheel: "<<width<<endl; vol = ((pie * (radius *radius) * length) * 2) cout<<"The volume of the axel is "<<vol<<" "<<"cubic inches"<<endl; }
else if (cin==3) { cout<<"Please enter the radius (of rod), the length of the rod & heigth of the cone"<<endl; cin>>radius>>length>>heigth; cout<<"Spear: "<<endl; cout<<"Radius of the rod: "<<radius<<endl; cout<<"Length of the rod: "<<length<<endl; cout<<"Height of the cone: "<<heigth<<endl; vol = (1/3 * pie * (radius * radius) * height) * 2; cout<<"The volume of the spear is "<<vol<<" "<<"cubic inches"<<endl;
return 0; }
I know it's a crazy one..but here is the assignment: Write a C++ program that calculates the volume of 3 different geometric shapes. Your program should give the user a menu like the following and repeat until the user wants to stop. Volume Calculation Program Select the Number of Your Chosen Object 1. Dumbbell 2. Axle 3. Spear When the user selects one of the 3 objects, the program should then request the appropriate measurements (in inches) and then calculate and display the volume of that object. The result should be printed showing cubic-inch units with 3 decimals of precision. Axle: 2 cylinders and a rod Dumbbell: two spheres and a rod Spears: two cones and a rod
Program requirements and Assumptions Formulas and Abbr. II P1 = 3.141 59 r radius = height (or length) Vol. of a sphere = 4I3flr3 Area of a circle = flr2 Vol. of a cylinder fl9b Vol. of a cone = 1/3fJr2h 1. The rod-end fits against the dumbbell ball snugly; there is no “air-gap’. You may assume that there is no loss of volume of the ball when the rod is fitted against it. 2. The radius of the dumbbell and axle center rods cannot be larger than half the radius of the ball or wheel. Do not make calculations if the rod radius is more than half of the ball or wheel radius. Give the user an error message instead. For example, if the user enters a radius of 5 inches for the ball or wheel, the rod radius must be no larger than 2.5 inches. 3. The spear’s cone base has exactly the same radius as the connecting rod. 4. Output is to both the monitor and the printer.
dude if and else r not cicluses, you need to do it using "do while" and "switch case" statements for now it is not correct... TRY HARDER
int a,b,c; int ht = 0;//height int radB = 0;//radius of sphere int radR = 0;//radius of rod int radC = 0;//radius cone int wt = 0;//width int lt = 0;//length int wh = 0;//radius of wheel const double pie = 3.14159;//pie double volsp = (4.0/3) * (radB * radB * radB) * pie;//volume of a sphere double volcy = pie * (radR * radR) * ht;//volume of cylinder/rod double volcn = (1.0/3) * (radC * radC) * pie * ht;//volume of cone
cin >> a; switch (a) { case 1: cout<<"Enter radius of Sphere "; cin>>radB; cout<<"Enter radius of rod "; cin>>radR; cout<<"Enter length of rod "; cin>>lt; float dumbbell = (volcy) + (volsp * 2); cout<<"The volume of the dumbbell is "<<dumbbell<<" cubic inches"<<endl; }
cin >>b; switch (b) { case 2: cout<<"Enter radius of wheel "; cin>>wh; cout<<"Enter radius of rod "; cin>>radR; cout<<"Enter length of rod "; cin>>lt; cout<<"Enter width of wheel "; cin>>wt;
double axle = (volsp * 3); cout<<"The volume of the axle is "<<axle<<" cubic inches"<<endl; }
cin >> c; switch (c) { case 3: cout<<"Enter radius of rod "; cin>>radR; cout<<"Enter length of rod "; cin>>lt; cout<<"Enter height of cone "; cin>>ht;
double spear = (volcn * 2) + volcn; cout<<"The volume of the spear is "<<spear<<"cubic inches"<<endl; }
return 0; }
Ok, so i made a bit of revision to my previous post. A few things: 1. I tried finding the volume of the Dumbbell(option 1) and it shows the result as being zero. 2. How to modify the program so that after the user calcualtes the volume of one object the program automatically goes back to the menu? 3. I'm kinna lost as how to calcualte the volume of the axle and spear.
1. I tried finding the volume of the Dumbbell(option 1) and it shows the result as being zero.
of course it does. you add together two zeros to get your result.
QUOTE
2. How to modify the program so that after the user calcualtes the volume of one object the program automatically goes back to the menu?
put it in a do-while loop
QUOTE
3. I'm kinna lost as how to calcualte the volume of the axle and spear.
why are you lost? what does a spear look-like? using only the simple shapes for which you've been given volumetric equations, how could you build a spear?
with regards to the results being zero, if i never set those variables to '0'...the compiler error would say that the variables haven't been initialized.
yes, but you haven't done anything to make them NOT zero. you need to perform the calculations and assign the result to your volume variable, after you have recieved the input from the user and stored the input in the appropriate parameters. just because you have written an equation in the source code doesn't mean that the equation is going to update every time you change a variable. you need a function to do that, or you just need to rewrite the equation where appropriate.
also, you switch-case control structure is a little off. you only have one case in each of three switch statements. the form for a switch-case control is:
CODE
switch (variable) { case value_1: { //do stuff if variable=value_1 } case value_2: { //do stuff if variable=value_2 } ... default: { //do stuff if variable is not equal to any of the specified case values } }
int a,b,c; int ht = 0;//height int radB = 0;//radius of sphere int radR = 0;//radius of rod int radC = 0;//radius cone int wt = 0;//width int lt = 0;//length int wh = 0;//radius of wheel const double pie = 3.14159;//pie double volsp = (4.0/3) * (radB * radB * radB) * pie;//volume of a sphere double volcy = pie * (radR * radR) * ht;//volume of cylinder/rod double volcn = (1.0/3) * (radC * radC) * pie * ht;//volume of cone
cin >> a; switch (a) { case 1: cout<<"Enter radius of Sphere "; cin>>radB; cout<<"Enter radius of rod "; cin>>radR; cout<<"Enter length of rod "; cin>>lt; double volsp = (4.0/3) * (radB * radB * radB) * pie;//volume of a sphere double volcy = pie * (radR * radR) * ht;//volume of cylinder/rod double volcn = (1.0/3) * (radC * radC) * pie * ht;//volume of cone float dumbbell = (volcy) + (volsp * 2); cout<<"The volume of the dumbbell is "<<dumbbell<<" cubic inches"<<endl; }
A dumbbell consists of two spheres and a cylinder. What is it that i'm overlooking. If i use the following info for dumbbell: radius of ball = 17. radius of the rod = 7. length of rod = 13. My professor said the answer should be 43160.211, however i get 41159...Thanx.
This post has been edited by zandiago: 1 Oct, 2007 - 07:18 PM
you're using the int datatype to store your values, which can only handle integer numbers. anything else gets truncated to an int. you should use the double datatype for all of your size measurements, otherwise you'll have this truncation problem.
that's because they are...right now, because of the way you have placed the curly braces, you have a switch statement with a single case, and then 2 more isolated case statements - and isolated case statements are not allowed.
look at my previous post with the simplified switch-case structures. your case statements need to be nested within the switch control block. and you don't want to have a separate cin statement to get a different variable for each case. the entire point of the switch-case control structure is to do something different, depending on the value of a single variable.
you want the test variable in your switch statement to be the variable that you accept the user input into. then your case labels must correspond to each of the potential inputs:
CODE
cin >> a; switch (a) { case 1: { //dumbell input, calculations, and display } case 2: { //axle input, calculations, and display } ... case 3: { //spear input, calculations, and display } }
oh, and with respect to the data type problem - make sure that all of your literals are the proper form as well. 3 is an int, 3.0 is a double. you'll want to use the double form for the literals you have in your equations.
hope that helps.
-jjh
This post has been edited by jjhaag: 2 Oct, 2007 - 06:21 PM