i need some help please i keep trying stuff out for this code but nothing works, can some one please help me out and tell me what i am doing wrong.
#include <iostream>
#define pi 3.1415926535
// Definition of the function (area of cone)
double cone_area(double height, double radius)
{
return (1/3)*pi*radius*height;
}
void main()
{
double raidus,height;
cout << "We are going to calculate the area of a cone" << end-el;
cout << "xxxxx" <<;
cin >> radius;
cout << endl;
cout << "yyyyy " <<;
cin >> height;
cout << "zzzzz" << cone_area(height,radius) << end-el;
}
here is the errors i get when i try to build it
1>------ Rebuild All started: Project: page 137 with constants, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'page 137 with constants', configuration 'Debug|Win32'
1>Compiling...
1>page 137 with constants.cpp
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(12) : error C2065: 'cout' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(12) : error C2065: 'end' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(12) : error C2065: 'el' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(13) : error C2065: 'cout' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(13) : error C2059: syntax error : ';'
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(14) : error C2065: 'cin' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(14) : error C2065: 'radius' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(15) : error C2065: 'cout' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(15) : error C2065: 'endl' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(16) : error C2065: 'cout' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(16) : error C2059: syntax error : ';'
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(17) : error C2065: 'cin' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(18) : error C2065: 'cout' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(18) : error C2065: 'radius' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(18) : error C2065: 'end' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(18) : error C2065: 'el' : undeclared identifier
1>Build log was saved at "file://c:\Users\tom\Documents\Visual Studio 2008\Projects\page 137 with constants\page 137 with constants\Debug\BuildLog.htm"
1>page 137 with constants - 16 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
here is the new code andthe errors iget with it can some one please help me figure this out.
#include <iostream>
#define pi 3.1415926535;
namespace
// Definition of the function (area of cone)
cone_area (double height, double radius);
{
return (1/3.0)*pi*radius*height;
}
void main()
{
double raidus,height;
cout << "We are going to calculate the area of a cone" << endl;
cout << "xxxxx";
cin >> radius;
cout << endl;
cout << "yyyyy ";
cin >> height;
cout << "zzzzz" << cone_area(height,radius) << end-el;
}
1>------ Rebuild All started: Project: page 137 with constants, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'page 137 with constants', configuration 'Debug|Win32'
1>Compiling...
1>page 137 with constants.cpp
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(5) : error C2059: syntax error : '('
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(6) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(13) : error C2065: 'cout' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(13) : error C2065: 'endl' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(14) : error C2065: 'cout' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(15) : error C2065: 'cin' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(15) : error C2065: 'radius' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(16) : error C2065: 'cout' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(16) : error C2065: 'endl' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(17) : error C2065: 'cout' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(18) : error C2065: 'cin' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(19) : error C2065: 'cout' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(19) : error C2065: 'radius' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(19) : error C2065: 'end' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(19) : error C2065: 'el' : undeclared identifier
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(19) : error C3861: 'cone_area': identifier not found
1>Build log was saved at "file://c:\Users\tom\Documents\Visual Studio 2008\Projects\page 137 with constants\page 137 with constants\Debug\BuildLog.htm"
1>page 137 with constants - 16 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
#include <iostream>
#define pi 3.1415926535; //This semicolon should not be there -
namespace //should be using namespace std;
// Definition of the function (area of cone)
cone_area (double height, double radius); //semicolon should not be here and function should have a return-type
{
return (1/3.0)*pi*radius*height;
}
void main() //should be int main() NOT void
{
double raidus,height; //misspelling of radius
cout << "We are going to calculate the area of a cone" << endl;
cout << "xxxxx";
cin >> radius;
cout << endl;
cout << "yyyyy ";
cin >> height;
cout << "zzzzz" << cone_area(height,radius) << end-el; // should be endl NOT end-el
}
#include <iostream>
#define pi 3.1415926535
using namespace std;
// Definition of the function (area of cone)
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 << "xxxxx";
cin >> radius;
cout << endl;
cout << "yyyyy ";
cin >> height;
cout << "zzzzz" << cone_area(height,radius) << endl;
}
1>------ Rebuild All started: Project: page 137 with constants, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'page 137 with constants', configuration 'Debug|Win32'
1>Compiling...
1>page 137 with constants.cpp
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\tom\documents\visual studio 2008\projects\page 137 with constants\page 137 with constants\page 137 with constants.cpp(8) : warning C4244: 'return' : conversion from 'double' to 'int', possible loss of data
1>Build log was saved at "file://c:\Users\tom\Documents\Visual Studio 2008\Projects\page 137 with constants\page 137 with constants\Debug\BuildLog.htm"
1>page 137 with constants - 1 error(s), 1 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
So you are missing a data type specifier for your function cone_area (double height, double radius)
It should be: double cone_area (double height, double radius)
because your function is going (i mean you want) to return a floating-point number (Optionally you can use float, but double has better precision (float 32 bits[S1,E8,M23], double 64 bits[S1,E11,M52])
here is the code i have and it works but the the teacher says it does not do what it is suppose to
#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 << "xxxxx";
cin >> radius;
cout << endl;
cout << "yyyyy ";
cin >> height;
cout << "zzzzz" << cone_area(height,radius) << endl;
}
here is what it says when i run it
we are going to calculate the area of a cone
xxxxx
and this is what the teacher wrote to me
There are no errors, but the program doesn’t do what it’s supposed to do – and it looks like it is sitting there waiting for you to input a value for the radius. You need to add prompts for the inputs, and see if the program actually calculates and outputs as it should.
#include <iostream>
#define pi 3.1415926535
usingnamespace 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" << cone_area(height,radius) << endl;
}
I can't go farther than that without know what the program is "supposed to do".
the assignment is
Use constants for pi, radius, and the height (since we haven't covered imputing 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 place. use proper formatting and appropriate comments
If you make cone_area return double (which it should, because it accepts arguments as double and returns a value related to the arguments) then it will return it's output to however many decimal places it uses. You could use printf ( http://www.cplusplus.com/reference/clibrary/cstdio/printf/ ) to do that. You also aren't commenting your code.
As constants, rather than use #define, which is a feature of C and the C preprocessor, you could define PI as const double PI.
I'm not sure what s/he means when s/he says to use constants for radius and height. What is this program meant to do if it doesn't take input???
the problem that it was all based on was
write a c++ program that computes and outputs the volume of a cone, given the diameter of its base and its height. the formula for computing the cone's volume is:
1/3pi x radius cubed x height
and then he wrote
Use constants for pi, radius, and the height (since we haven't covered imputing 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 place. use proper formatting and appropriate comments
You need to comment your code then, and I'm still unsure of exactly how your program relates. This is how I'd do it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <cmath>
int main() {
constdouble pi = 3.1415926535; // pi cannot be modified
int height = 0, radius = 0; // Initialize two integers, height and radius, to 0.
std::cout << "Please enter the height: ";
std::cin << height;
std::cout << "\nPlease enter the radius: ";
std::cin << radius;
// Now we have the height and radius, we can calculate the result:
std::cout << "\nResult: " << (1 / 3.0 * pi) * (pow(radius, 3) * height) << "\n";
std::cin.get();
return 0;
}
Note that that's just an example.
Or have you got to use a function?
Oh and you aren't cubing (x3) your radius. It says radius cubed. You will need to use the pow() function which is included in math.h (or cmath in the stl).
now this is what the teacher had to say
You still haven’t showed me the program running. You have no prompts for the input, and have apparently not input anything. You don’t know if it works or not so can someone please help me and let me know what he means so i can get this assignment done