d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ Assignment > Volume Of A Sphere
Add Reply New Topic New Poll
Member
Posts: 1
Joined: Oct 8 2013
Gold: 0.00
Oct 9 2013 05:25am
Hi all,

i have got a complex assignment. below is what the assignment talk about

1. write a program to calculate the volume of a sphere with a radius, r. The volume is given by this formula
Volume = 4πr3
3

Answer the following questions:
a) Write complete program requirements specification for this problem.
b) Determine the output required by the program.
c) Determine how many inputs the program will have.
d) What is the C++ formula for converting the input items into output items.
e) Do a hand calculation for the given input value.
f) Provide a solution algorithm for this problem
g) Code the program in C++


This is the codes that i have so far, but its giving me a little bit of headache with errors

#include <iostream>
#include <cmath>
using namespace std;


int main(){

//Input radius, volume, initialValue, increment, ending Value,
double x, volume, initialRadius, increment, endingRadius, radius;
#define PI 3.14159



//Output Volume of Sphere, Radius,
cout<<" Please input the initial radius of the sphere: "<<endl;
cin>>initialRadius;
cout<<"Please input your increment value: "<<endl;
cin>>increment;
cout<<"Please input the final radius of the sphere."<<endl;
cin>>endingRadius;

for (x=initialRadius;x<=endingRadius; x = x + increment)
{ radius = x;
volume=4/3.0*PI*pow(radius,3);
cout<<"The Volume of a sphere with a radius of "<<radius<<" mm is "<<volume<<" mm3."<<endl;
}


cin.get();
return 0;
}


The code is not totally running due to errors. i need a little bit of correction. thank you.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 9 2013 06:20am
it's not like we need to know what the errors are or anything....
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Oct 9 2013 05:51pm
not really a programming comment, but you said:
Quote
1. write a program to calculate the volume of a sphere with a radius, r.
But you seem to be trying to do much more than that, with that start radius, increment, ending radius stuff (I know what your trying to do with that, but it seems like that is not the task you were given).

This post was edited by Azrad on Oct 9 2013 05:52pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll