Output problems with homework-first time posting

Hello everybody this is my first time posting here, and first time learning c++.
I am having trouble with my homework assignment where I am supposed to write four
functions that return the area of a circle, cylinder , and volumes of a cone and cylinder. The problem that I am having is with my output. whenever I enter in a radius and height all of my functions return just a 1. If you want to flame my code or my post go ahead. Criticism can be a good thing.

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>            /
#include <string>              
#include <math.h>              
using namespace std;

#define  PI1  3.14157



float areaCircle(float radius)
{
      float area; 
      area = PI1*radius*radius;
     
} 
float circumCircle(float radius) 
{
      float circum; 
      circum = PI1*radius*2;
      return circum; 
}
float areaCylinder(float radius, float height)
{
      float area;      
      area = 2*PI1*radius*height+2*PI1*radius*radius;
      return area;
}
float volumeCylinder(float radius, float height)
{
      float volume; 
      volume = PI1*radius*radius*height;
      return volume; 
}
float volumeCone(float radius, float height)
{
      float volume;
      volume = (1.0/3)*(PI1*radius*radius*height);
      return volume;
}

      
int main()
{  float radius; 
   float height;
   
    cout << " Please enter a radius : ";
    cin >> radius;
    cout << endl;
    cout << " Please enter a height : ";
    cin >> height; 
    cout << endl;
    
    cout << " The radius is : " << radius << endl;
    cout << " THe height is : " << height << endl;
    cout << endl << endl; 
    
    cout << " The area of a circle is          : " << areaCircle << endl;
    cout << " The circumference of a circle is : " << circumCircle << endl;
    cout << " The area of a cylinder is        : " << areaCylinder << endl; 
    cout << " The volume of a cylinder is      : " << volumeCylinder << endl; 
    cout << " The volume of a cone is          : " << volumeCone << endl;
    cout << endl; 
	system("PAUSE");
	return 0;
 
Last edited on
Please use code tags. It makes code easier to read. They are the "<>" on right side of text box.

3 things

1. You forgot to return a value from your areaCircle function.
2. It's bad practice to use system("PAUSE");.
3. You need to pass the variable to all your functions. For example your first output using a function would look like cout << " The area of a circle is : " << areaCircle(radius) << endl;. You will need to fix the rest of your function calls.
Thank you for your responses joe that worked. Also why is it bad practice to use system("Pause"); ?
In short, it's slow, platform dependent, insecure. If you would like to learn more their several good explanations here: http://stackoverflow.com/questions/1107705/systempause-why-is-it-wrong
Nothing's wrong with std::system() in the general case, however, it's important to know what it does:

a.) its behavior depends on the system's environment -- it can be a security risk, and unreliable;
b.) it takes an otherwise portable program and makes it less portable.

Also, keep in mind that non-interactive use and versatility is the greatest strength of a command-line interface, and forcing someone to press (or simulate) a keystroke to use your program seriously impedes its usefulness.
Last edited on
Topic archived. No new replies allowed.