i am new to C++ and don't understand it to well. the question is
Copy and paste your existing cone program into a new .cpp file. Modify the code to calculate the volume and total surface area of a right circular cylider. Also convert the volume (in cubic inches) to gallons. I believe there are 231 cubic inches per gallon, but you should look this up. Output all this, along with the input data.
here is what i got and all it shows is the volume
#include <cmath>
Please use [code][/code] tags around your code; and you don't need so many spaces between lines. In any case, the error is on the line where you display the surface area; you are missing a double quote (") and are using the wrong variable name (should be SurfaceArea not surface area).
ok tried that but all it does is shows me the volume and say please press any key and when i hit a button it closes it does not say anything about the surface area
cout << "SurfaceArea is: " << surface area << endl;
return 1;
}
1>------ Build started: Project: vol,area,gal, Configuration: Debug Win32 ------
1>Compiling...
1>vol,area,gal.cpp
1>c:\users\ringler\documents\visual studio 2008\projects\vol,area,gal\vol,area,gal\vol,area,gal.cpp(1) : warning C4627: '#include <cmath>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\ringler\documents\visual studio 2008\projects\vol,area,gal\vol,area,gal\vol,area,gal.cpp(3) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\ringler\documents\visual studio 2008\projects\vol,area,gal\vol,area,gal\vol,area,gal.cpp(59) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>Build log was saved at "file://c:\Users\ringler\Documents\Visual Studio 2008\Projects\vol,area,gal\vol,area,gal\Debug\BuildLog.htm"
1>vol,area,gal - 1 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
this is the new formula and the error i got when i tried to debug it. the instructor for the course said to check the header out can someone tell me what i am doing wrong.
}
1>------ Build started: Project: vol,area,gal, Configuration: Debug Win32 ------
1>Compiling...
1>vol,area,gal.cpp
1>c:\users\ringler\documents\visual studio 2008\projects\vol,area,gal\vol,area,gal\vol,area,gal.cpp(1) : warning C4627: '#include <cmath>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\ringler\documents\visual studio 2008\projects\vol,area,gal\vol,area,gal\vol,area,gal.cpp(3) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\ringler\documents\visual studio 2008\projects\vol,area,gal\vol,area,gal\vol,area,gal.cpp(59) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
1>Build log was saved at "file://c:\Users\ringler\Documents\Visual Studio 2008\Projects\vol,area,gal\vol,area,gal\Debug\BuildLog.htm"
1>vol,area,gal - 1 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
1>c:\users\ringler\documents\visual studio 2008\projects\vol,area,gal\vol,area,gal\vol,area,gal.cpp(1) : warning C4627: '#include <cmath>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
First try adding #include <stdafx.h> to the top of your code.
ie it should be the first include.
or you could go to the project properties and turn of the use of precompiled headers..
if this fails start a new project, either an empty one or deselect use precompiles header in the options, then cut and paste your code into the new project.
To turn off the use of precompiled header:
Go to the solution explorer and right click on the top of the projects tree and select Properties.
In the properties pages, select All configurations in the configuration drop down.
Navigate to configuration properties ->C/C++->Precompiled header, and change create /use precompiled headers to Not using precompiled headers.
#include <cmath>
#include <iostream>
usingnamespace std;
int main()
{
float radius, height, volume, length, SurfaceArea;
// Obtain radius from user input
cout << "Please enter radius: ";
cin >> radius;
// Obtain height from user input
cout << "Please enter height: ";
cin >> height;
// calculate volume of cone
volume = 3.1415927 * radius * radius * height;
// display volume
cout << "Volume is: " << volume << endl;
// calculate surface area of cone
SurfaceArea = 3.1415927 * radius * radius + 3.1415927 * radius * length;
// display surface area
cout << "The surface area is: " << SurfaceArea << endl;
system("PAUSE");
return 0;
}
I use Dev so I don't need the stdafx.h, and I prefer less spaces, you didn't declare the length variable or ask for it. Even after being told that you forgot the quotation (") after the surface area you still were missing it. ummm. The system("PAUSE"); was laziness of mine, I don't know why you had return 1; oppose to return 0; and if you used return 0; I'd ask why you didn't use return EXIT_SUCCESS;.