question

Pages: 12
Sep 5, 2009 at 7:26pm
No, don't put in using namespace std; or are you confident that you're going to use EVERYTHING in the standard namespace? The standard namespace is huge.

Putting std:: before cout, string, cin, flush and endl isn't that difficult... jeez. You can even declare using std::cout, but why use the entire standard namespace when you don't need EVERYTHING that's inside it?
Oct 27, 2009 at 10:19am
hello this is the formula that i have right now. can someone please help me?
#include <iostream>
#define pi 3.1415926535
using namespace std;

// Definition of the function (area of cone)
int cone_area (double height, double radius)
{
return (1/3.0)*pi*radius*height;
}

int main()
{
double radius,height;
cout << "We are going to calculate the area of a cone" << endl;
cout << "Please enter a number in the format xxxxx ";
cin >> radius;
cout << "\n";
cout << "Please enter a number in the format yyyyy ";
cin >> height;
cout << " zzzzz is " << cone_area(height,radius) << endl;
}

and this is what the teacher had to say about my program
For this homework, you use “constants”, which means you declare the values for the height and radius in the program itself – you don’t have to prompt for and get the values from the user. You do have to have the program calculate the answer correctly, which your program doesn’t do. You also need to format the answer as specified in the assignment, which your program also doesn’t do. Fix these things.

this is the assignment
Programming Assignment 1: Do Problem 1 on page 137. Use constants for pi, the radius, and the height (since we haven't covered inputing data yet - although you might have already read about it in Chapter 4). Format the output as shown below:

Radius Height Volume
xxxxx yyyyy zzzzz

Output 2 decimal places. Use proper formatting and appropriate comments. if you need anything else just let me know please.

Oct 27, 2009 at 12:31pm
The teacher's comments are pretty clear.

Use constants for pi, radius, and height. Your program has a constant for pi, but asks the user to enter the
other two. Make constants for radius and height, just like pi, but with whatever values you want. Then
remove your code to prompt the user to enter numbers and read the input.

Then, you have to use stream manipulators to output the result to two decimal places.
Oct 28, 2009 at 3:03am
how wouldi do that ? i'm am new to this all.
Oct 28, 2009 at 3:37am
this is the new code i got can someone tell me if i am missing anything or not cause it is still asking me for inputs
#include <iostream>
#define pi 3.1415926535
#define radius 10000.00
#define height 20000.00
using namespace std;

// Definition of the function (area of cone)
int cone_area (double height, double radius)
{
return (1/3.0)*pi*radius*height;
}

int main()
{
double radius,height;
cout << fixed << setprecision(2) << " zzzzz is " << cone_area(height,radius) << endl;
}
Oct 28, 2009 at 4:20am
You probably want to rename your function arguments, because they will be replaced by the #defines as well, name them something like h and r. Other then that, I think you are good to go.
Oct 30, 2009 at 12:44pm
i have renamed it and here is the code i got right now

#include <iostream>
#define pi 3.1415926535
#define radius 10000.00
#define height 20000.00
using namespace std;


int cone_area (double height, double radius)
{
return (1/3.0)*pi*radius*height;
cout << fixed << setprecision(2) << " zzzzz is " << cone_area(height,radius) << endl;
}
it is still asking me to input numbers will someone please help me i am lost
Nov 16, 2009 at 5:09pm
can someone please look at this and let me know what i am doing wrong.
Nov 16, 2009 at 5:36pm
Your main() function asks the user to enter the numbers....
Nov 17, 2009 at 12:58am
yes and how can i stop it from doing that cause all i want it to do is give me the cone area using the numbers i put in the code
Nov 17, 2009 at 1:48am
yes and how can i stop it from doing that cause all i want it to do is give me the cone area using the numbers i put in the code


are you saying you want to define the variables within the code instead of from user input? If this is the case, just take out the cin statements and put at the beginning of your main function:

radius = some number
height = some number
Topic archived. No new replies allowed.
Pages: 12