donut shape

hey guys I need help please tell me what i am doing wrong


Create a file that will contain the following functions:

VolSphere()
AreaSphere()
VolCone()
AreaCone()
VolCylinder()
AreaCylinder()
VolDonut()

Hint: Donut/Torus volume = 2 * pi * pi * R * r * r

Today's diet will consist of the following junk food:
An ice cream cone 4.5" high with a diameter of 2.5" on top. The cone is filled with ice cream.
On top of the cone sits two scoops (spheres) of chocolate ice cream, each with a diameter of 3".
For desert, you will eat a half dozen Krispy Kreme donuts (toruses). Each 4" diameter donut has a 2" diameter hole.

Write a program that will calculate the approximate total volume of junk food you will eat today. Use any necessary functions from your file. Hint: You may need to convert the numbers used above to the types of numbers used by your functions.

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
38
39
40
41
42
43
44
45
46
47
48
49
1st file
 float VolSphere(float r)
{
        return 4.0/3.0* 3.14 * r * r * r;
}
 float AreaSphere(float a,float h)
{
        return (sqrt(r * r + h * h));
 float VolCone(float v)
{
        return 1/3 * b * h;
}
 AreaCone(float c,float s)
{
        return 3.14 * r * s;
}
 VolCylinder(float b,float h)
{
        return 3.14 * r * r * h
}
 AreaCylinder(float g)
{
        return
}
 VolDonut(float d)
{
        return
}



main program


#include <iostream>
using namespace std;
#include "geometry.h"


main ()
{
        cout<< "the volume is "<< 2 * volsphere(1.5) + Volcone
}







can anyone tell me what i am missing am not very good at this class
Some small things:
1. after line 8, close the curly bracket }
2. line 19 is missing a semicolon;
3. Area of cylinder is not implemented. If you don't need it now, or in the future, just comment it out
4. Volume of the torus is not implemented. You would need two parameters, inner radius and outer radius
5. Finish line 42
thank ats15

so for the area of cylinder can i use return 2 * 3.14 * r ( h + r); ?

i dont know what formula to use for volume of donut?

would like 42 be 2 * pi * pi * R * r * r
Correct for both. Don't forget to convert diameter to radius.
ok can u look at these error i am getting.

this is my geometry.h 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
25
26
27
28
29
 float VolSphere(float r)
{
        return 4.0/3.0* 3.14 * r * r * r;
}
 float AreaSphere(float r,float h)
{
        return (sqrt(r * r + h * h));
}
 float VolCone(float b, float h)
{
        return 1/3 * b * h;
}
 AreaCone(float r,float s)
{
        return 3.14 * r * s;
}
 VolCylinder(float r,float h)
{
        return 0.3333 * 3.14 * r * r * h;
}
 AreaCylinder(float r, float h)
{
        return 2 * 3.14 * r ( h + r);
}
 VolDonut(float r)
{
        return 2 * pi * pi * r * r * r;

}


this is the main code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;
#include "geometry.h"


main ()
{
        cout << "Today's diet will consist of the following junk food":;
        cout << "An ice cream cone 4.5\" high with a diameter of 2.5\" on top.  The cone is filled with ice cream";
        cout << "On top of the cone sits two scoops (spheres) of chocolate ice cream, each with a diameter of 3".
        cout << "For desert you will eat a half dozen Krispy Kreme donuts toruses.  Each 4\" diameter donut has a
        2\" diameter hole." << endl;

        cout << "the volume is "<< 2 * VolSphere(1.5) + VolCone(1.25,4.5) + 6 * VolDonut (1.25,0.5);


}



this is the error i am gettin
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
shphere.cpp:11: error: missing terminating " character
shphere.cpp:12: error: stray â\â in program
geometry.h: In function âfloat AreaSphere(float, float)â:
geometry.h:8: error: âsqrtâ was not declared in this scope
geometry.h: At global scope:
geometry.h:14: error: ISO C++ forbids declaration of âAreaConeâ with no type
geometry.h: In function âint AreaCone(float, float)â:
geometry.h:16: warning: converting to âintâ from âdoubleâ
geometry.h: At global scope:
geometry.h:18: error: ISO C++ forbids declaration of âVolCylinderâ with no type
geometry.h: In function âint VolCylinder(float, float)â:
geometry.h:20: warning: converting to âintâ from âdoubleâ
geometry.h: At global scope:
geometry.h:22: error: ISO C++ forbids declaration of âAreaCylinderâ with no type
geometry.h: In function âint AreaCylinder(float, float)â:
geometry.h:24: error: ârâ cannot be used as a function
geometry.h: At global scope:
geometry.h:26: error: ISO C++ forbids declaration of âVolDonutâ with no type
geometry.h: In function âint VolDonut(float)â:
geometry.h:28: error: âpiâ was not declared in this scope
shphere.cpp: In function âint main()â:
shphere.cpp:8: error: expected `;' before â:â token
shphere.cpp:11: error: request for member âcoutâ in â"On top of the cone sits two scoops (spheres) of chocolate ice cream, each with a diameter of 3"â, which is of non-class type âconst char [95]â
shphere.cpp:12: error: expected `;' before string constant
geometry.h:26: error: too many arguments to function âint VolDonut(float)â
shphere.cpp:14: error: at this point in file 



can someone tell me what i am doing wrong








You can't put line breaks in the middle of a string literal:

1
2
3
4
5
6
7
8
9
10
11
12
cout << "This is bad
and will error";

// can't put a new line after 'bad'

cout << "This is ok and will be just fine";

// if you want to break up the line, you can put to literals together and it'll
//   automatically join them:

cout << "This is also okay"    // <- notice we end this literal on this line
        " and will work fine."; // <- before starting this one 
Last edited on
ok i will look into that but i still get geometry.h errors do you know what i am missing
Assuming that you have only fixed the broken lined string literals...
These errors are pretty self-explanatory. If the compiler says missing ';' then put in the missing semi-colon. It even tells you what line they are missing from.

"geometry.h:26: error: too many arguments to function âint VolDonut(float)â"

This literally means, too many arguments. Look at VolDonut(float r). It only takes 1 argument and you are trying to call it with too many on line 26.

"geometry.h:8: error: âsqrtâ was not declared in this scope"

sqrt is not declared anywhere. You probably forgot to include <cmath>, which is a library containing the square root function with that syntax.

Everywhere it says ISO forbits naming <some name or other> with no type, give them a type. If you're returning floats, then obviously that is the type you need.

Anyway, sorry, I feel like I'm being a bit short with this post, but you have to learn to read these errors dude. The compiler often gives lots of information about what the error is and a line number where it thinks the error is. These error messages are things you are going to see time & time again and you need to be able to think for yourself and sort most of them out yourself.
Also, if you ask on the forum a question, don't say you still get errors, tell us what errors, show us the piece of code you think the error is in.
but i still get geometry.h errors do you know what i am missing
Last edited on
thank you guys so much.

sorry i am old and not very good with computers


ok well these errors i just cant quite figure them out.

1
2
3
4
shphere.cpp: In function âint main()â:
shphere.cpp:12: error: invalid operands of types âconst char [22]â and â<unresol                                                                                        ved overloaded function type>â to binary âoperator<<â
geometry.h:28: error: too many arguments to function âfloat VolDonut(float)â
shphere.cpp:14: error: at this point in file


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
GNU nano 1.3.12                                          File: shphere.cpp

#include <iostream>
using namespace std;
#include "geometry.h"
#include "math.h"

main ()
{
        cout << "Today's diet will consist of the following junk food:";
        cout << "An ice cream cone 4.5 inches high with a diameter of 2.5 inches on top.  The cone is filled with ice cream";
                "on top of the cone sits two scoops of chocolate ice cream, each with a diameter of 3.";
                "For desert you will eat a half dozen Krispy Kreme donuts.  Each 4 inch diameter donut has a";
                "2 inch diameter hole." << endl;

        cout << "the volume is "<< 2 * VolSphere(1.5) + VolCone(1.25,4.5) + 6 * VolDonut (1.25,0.5);


}




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 <iostream>
#include <math.h>

 float VolSphere(float r)
{
        return 4.0/3.0* 3.14 * r * r * r;
}
 float AreaSphere(float r,float h)
{
        return (sqrt(r * r + h * h));
}
 float VolCone(float b, float h)
{
        return 1/3 * b * h;
}
 float AreaCone(float r,float h)
{
        return 3.14 * r * (sqrt(r * r + h * h));
}
float VolCylinder(float r,float h)
{
        return 0.3333 * 3.14 * r * r * h;
}
float AreaCylinder(float r,float h)
{
        return 2 * 3.14 * r * ( h + r);
}
float VolDonut(float r)
{
        return 2 * 3.14 * 3.14 * r * r * r;

}




"geometry.h:28: error: too many arguments to function âfloat VolDonut(float)â
shphere.cpp:14: error: at this point in file"

This is because:
float VolDonut(float r) <-- This takes one argument, float r

But here in main.
1
2
cout << "the volume is "<< 2 * VolSphere(1.5) + VolCone(1.25,4.5) + 6 * VolDonut (1.25,0.5);
//- 2 arguments, but it can only take 1.  


shphere.cpp: In function âint main()â:
shphere.cpp:12: error: invalid operands of types âconst char [22]â and â<unresol


This particular error is a little more cryptic. The compiler is complaining because you put semi-colons at the end of all your string pieces.
1
2
3
4
cout << "An ice cream cone 4.5 inches high with a diameter of 2.5 inches on top.  The cone is filled with ice cream"; //<
                "on top of the cone sits two scoops of chocolate ice cream, each with a diameter of 3."; //< 
                "For desert you will eat a half dozen Krispy Kreme donuts.  Each 4 inch diameter donut has a"; //<
                "2 inch diameter hole." << endl;


If you split up a string in this way, the semi-colon only comes at the very end of the string. ;)

Edit: Missed out a tag.
Last edited on
Topic archived. No new replies allowed.