homework question?

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>



#include <iostream>



using namespace std;







int main()



{



double radius, height, volume;







// 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;











// Obtain radius from user input



cout << "Please enter radius: ";



cin >> radius;







// Obtain height from user input



cout << "Please enter height: ";



cin >> height;




// calculate surface area of cone



SurfaceArea = 3.1415927 * radius * radius + 3.1415927 *radius *length;







// display surface area



cout << "surface area << surface area << endl;



return 0;



}
any help will help me out
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).
not to sound stupid but what do you mean by use tags. if you can show me an example please.
[code]
int main()
{
cout << "Hello";
return 0;
}
[/code]

becomes

1
2
3
4
5
int main()
{
    cout << "Hello";
    return 0;
}
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
Last edited on
when i hit a button it closes it does not say anything about the surface area


http://www.cplusplus.com/forum/beginner/1988/
still doing what i said it shows volume but that is it nosurface area and after the volume is showed it closes
there is no way this code compiles. You never declare SurfaceArea and you mispell it when you try to print it out.
#include <cmath>

#include <iostream>

using namespace std;



int main()

{

double radius, height, volume;



// 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 << "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.
closed account (z05DSL3A)
First try adding #include <stdafx.h> to the top of your code.

Basically you have setup a project to use precompiled headers and then deleted to code that calls them.
can some one please help me here is what i got for the code and the error i am getting

#include <cmath>

#include <iostream>

#include <stdafx.h>

using namespace std;



int main()

{

double radius, height, volume;



// 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 << "SurfaceArea << SurfaceArea << 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 ==========

closed account (z05DSL3A)
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.
Last edited on
I don't think the header is <stdafx.h>
Isn't it "stdafx.h"?
I edited your code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <cmath> 
#include <iostream>
using namespace 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;.
Last edited on
i got it to show the surface area, so now how would i go about converting the surface area from inches to gals useing the same program
sorry i ment volume from cubic in to gal the formula i got is 1 gal is equal to 231 cubic inches so how would i figure it out and add it to my code
Well, you know the volume in some units, how would you convert the volume to the other units?
i am just tryingto figure out how to add it to the code above
Not sure if this is what you're looking for but it worked for me.

ps. I'm new to C++ too so if I've done some things wrong I'm sorry.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <cmath>
#include <iostream>
using namespace std;
void convert ();
double radius, height, volume, length, SurfaceArea;

int main()
{
    // 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 << " gal." << 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;
    cout << "\n";
    convert();
    cout << "\n";
    system("PAUSE");
    return 0;
}

void convert (){
    double i;
    i = volume * 231;
    cout << i << " is the volume converted to ci from gal.\n";
}


i want to thank everyone here for the help, i have used many forums in the past and the folks on here are nicer and very helpful
Topic archived. No new replies allowed.