Geometry Calculator with functions

Hello all, sorry if this question is in any way derivative. I searched through a lot of other similar questions, but I didn't find anything that was exactly the same.
This is a homework assignment, for an online-only class (huge mistake!) I have spent a lot of time on it, but apparently still do not understand functions. I am having so much trouble with this, I am probably making stupid mistakes because I have looked at it too many times.



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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <iostream>
#include <iomanip>

using namespace std;

int displayMenu();
double calcAreaCircle( double radius ); 	 
double calcAreaRect( double length, double width ); 	
double calcAreaTriangle( double base, double height ); 

const double Pi = 3.14159;

int main ()
{
    double menu;
    menu=displayMenu();
    
    double circ_area;
    circ_area = calcAreaCircle ();
  
    double rect_area
    rect_area = calcAreaRect ();
    
    double tri_area
    tri_area = calcAreaTriangle ();
    
       switch(choice) 
        {        
            case 1:
            {
                cout << "Please enter the Radius:" << endl; 
                cin >> radius;
             }   
                break;

            case 2:
            {
                cout << "Please enter the Length:" << endl; 
                cin >> length; 
                cout << endl; 
 
                cout << "Please enter the width:" << endl; 
                cin >> width; 
                cout << endl; 
              } 	
            break;

            case 3: 
            {
                cout << "Please enter the Base:" << endl; 
                cin >> base; 
                cout << endl; 
 
                cout << "Please enter the Height:" << endl; 
                cin >> height; 
                cout << endl; 
  
              } 
             
            break;

            case 4:
            cout<< "Thank you for using the geometry calculator, Bye! "<<endl;
            system ("pause");	 
            break; 
   
       } 
     
 }  
 
 int displayMenu()
{
    int choice;	

    cout << "Geometry Calculator"<<endl; 
    cout << "1. Calculate the Area of a Circle"<<endl; 
    cout << "2. Calculate the Area of a Rectangle"<<endl; 
    cout << "3. Calculate the Area of a Triangle"<<endl; 
    cout << "4. Quit"; 
    cout << endl;
    cin >> choice;

    
    while (choice < 1 || choice > 4)
    {
        cout << "Invalid selection. Enter 1, 2, 3, or 4: ";
        cin >> choice;
    }
    
}
    
return choice;
}


 double calcAreaCircle(double radius)	 
    {
     
        double circ_area = Pi*radius*radius; 
  
    if (radius > 0)	  
     {	  
      cout << "The area of the circle " << radius << " is: " << area << endl;
	  system ("pause"); 
        return 0; 
     } 
    else	
    { 
        cout << "You did not enter a valid number" << endl; 
        cout << "The program will now restart" << endl; 
        system ("pause"); 
        return circ_area;
    } 
    } 
 
 
double calcAreaRect (double width, double length)	
  { 
    double rect_area = length * width
    
    if (length > 0, width > 0)	  
     {	  
        cout << "The Area for the Rectangle is: " << area << endl; 
        system ("pause"); 
        return area; 
     } 
 
    else	
     {	  
        cout << "You did not enter valid numbers." << endl; 
        cout << "The program will now restart." << endl; 
        system ("pause"); 
        return rect_area; 
     } 
} 
 
double calcAreaTriangle (double base, double height )
  {
    double tri_area = base * height
        
 
    if (base > 0, height > 0)		
     {	
        area = .5 * base * height;
     } 
    else	
     {	  
        cout << "You did not enter a valid number." << endl;	
        cout << "The program will now restart." << endl; 
        system ("pause"); 
        return tri_area; 
   } 

}



I am getting many errors, especially where the switch case is concerned. I would appreciate any help, even a tip in the right direction would be extremely helpful.
Thanks
For one, displayMenu() needs to return a value of type int. Two, you need to pass a value to the functions themselves. In the parenthesis after you make the function calls (such as calcAeraTriangle() on line 25) you actually have to put the two variables who hold the value for length and with that you want to use. Three, for the three functions you do have for calculations, they need to have their returns (return area, return rect_area, et cetera) outside of the if-else loop. Also, you keep referring to a variable called area... There is no variable called area. Fourthly, you need the function calls to be after you actually have something to put on for base and height, or radius. Put them inside of the switch statement for their respective area. Fifthly, your switch statement refers to a variable choice. There is no variable choice. You want to replace that with menu. The variable "choice" in menu is limited to the menu function. Inside of main(), the variable choice does not exist.
Topic archived. No new replies allowed.