Can't Compile Program Control/Specific Task Function Program

I have to make a program with program control and specific task functions. I'm supposed to call 2 specific task functions to my program. I wrote the code for them in the process_area, but I can't compile the program at all. I'm not sure what's wrong with the 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
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
  
// Headers and Other Technical Items

#include <iostream>
using namespace std;
#include "C:\\Dev-Cpp\\user_library\\udst_monitor.h"
#include "C:\\Dev-Cpp\\user_library\\udst_geo_area.h"

// Function Prototypes

void get_data(void);
void process_data(void);
void show_results(void);

// Variables

double  rectangle_length;
double  rectangle_width; 
double  total_area_of_property;
double  farmable_area_in_acres;
double  non_farmable_area_in_acres;
int     square_ft_acre; 


//******************************************************
// main
//******************************************************

int main(void)
  {
  get_data();
  process_data();
  show_results();

  return 0;
  }

//******************************************************
// get data
//******************************************************  
  
void get_data(void)
  {
  
  cout << "\nEnter the length of the property in feet --->: ";
  cin >> rectangle_length;
  cout << "\nEnter the width of the property in feet ---->: ";
  cin >> rectangle_width;

  
  return;
  }
  
//******************************************************
// process data
//******************************************************

void process_data(void)
  {

//******************************************************
// area_rectangle
//******************************************************

double area_rectangle(double side1, double side2)
  {
  return side1 * side2 / 43560 ;
  }

//******************************************************
// area_circle
//******************************************************

double area_circle(double radius)
  {
  return 3.14159265 * radius * radius /43560 ;
  }
 
  
 
//******************************************************
// non_farmable area
//******************************************************         
  
  non_farmable_area_in_acres = total_area_of_property - farmable_area_in_acres;               
                       
 
  return;
  }


//******************************************************
// show results
//******************************************************

void show_results(void)
  {
  
  cout << "\n";
  cout << "\nThe total area of the property in acres is ---->: ";
  cout << total_area_of_property;
  cout << "\nThe total farmable area in acres is -----> ";
  cout << farmable_area_in_acres;
  cout << "\nThe total non-farmable area in acres is -----> ";
  cout << non_farmable_area_in_acres;  


  pause_m();

  return;
  }



//******************************************************
// End of Program
//******************************************************

Can you copy and paste the compile errors you are getting?

Also, Dev-C++, unless you have the updated version which is harder to find, is incredibly outdated:
http://www.cplusplus.com/articles/36vU7k9E/
I'm pretty sure I have the updated version.

Here are the errors:

In function `void process_data()':

78 a function-definition is not allowed here before '{' token

78 expected `,' or `;' before '{' token

87 a function-definition is not allowed here before '{' token

87 expected `,' or `;' before '{' token

I was told:

Within your process_data function call the following two (2) user designed specific task functions that are defined in the udst_geo_area.h file.

area_rectangle
and
area_circle

So I pasted and copied the formulas I had for them in the process_data area. I thought the program was going to work, but I have all those erros.
Last edited on
In your code you defined the functions inside of another function instead of calling them. Define the functions outside of the process data function and call them inside of the process data function.
I thought I had defined them in another file though?

Here's the udst_geo_area file:

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

//******************************************************
// area_square
//******************************************************

double area_square(double side)
  {
  return side * side;
  }

//******************************************************
// area_rectangle
//******************************************************

double area_rectangle(double side1, double side2)
  {
  return side1 * side2;
  }

//******************************************************
// area_circle
//******************************************************

double area_circle(double radius)
  {
  return 3.14159265 * radius * radius;
  }

//******************************************************
// area_trapezoid
//******************************************************

double area_trapezoid(double base, double top, double height)
  {
  return (base + top) / 2 * height;
  }


//******************************************************
// area_triangle
//******************************************************

double area_triangle(double base, double height)
  {
  return (base * height) / 2;
  }  


//******************************************************
// End of File
//******************************************************

Last edited on
Look, on line 58 you start the definition of a function, the on line 65 you start the definition of another function inside the function on line 58:
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
//******************************************************
// process data
//******************************************************

void process_data(void)
  {

//******************************************************
// area_rectangle
//******************************************************

double area_rectangle(double side1, double side2)
  {
  return side1 * side2 / 43560 ;
  }

//******************************************************
// area_circle
//******************************************************

double area_circle(double radius)
  {
  return 3.14159265 * radius * radius /43560 ;
  }
 
  
 
//******************************************************
// non_farmable area
//******************************************************         
  
  non_farmable_area_in_acres = total_area_of_property - farmable_area_in_acres;               
                       
 
  return;
  }
Last edited on
That whole calling part is confusing me. What should I use instead in that area (sorry if it comes off as sounding off). I'm extremely confused.

Here's the pseudocode:


Function main
Pass In: nothing
Call: get_data
Call: process_data
Call: show_results
Pass Out: zero to the OS
Endfunction

********************

Function get_data
Pass In: nothing
display a message asking user for the length of the property in feet
get the length of the rectangle in feet from the keyboard
display a message asking user for the width of the property in feet
get the width of the rectangle in feet from the keyboard
Pass Out: nothing
Endfunction

********************

Function process_data
Pass In: nothing
Calculate the total area of the property in acres by:
1.Calling the area_rectange function passing in length and width
2.then dividing by the number of square feet in an acre
Calculate the farmable area in acres by:
1.Calling the area_circle function passing the radius
2.then dividing by number of square feet in an acre
Calculate the non-farmable area in acres by:
1.subtracting farmable area from the property area
Pass Out: nothing
Endfunction

********************

Function show_results
Pass In: nothing
display the total area of the property in acres with an appropiate message
display the farmable area in acres with an appropiate message
display the non-farmable area in acres with an appropiate message
Call: pause_m
Pass Out: nothing
Endfunction

******************************************************

Potential Constans

Data Type Identifier Name
******** *********
integer square_ft_acre Note: 1 ft= 43560 acres

Potential Variables

Data Type Identifier Name
********* ***************
double rectangle_length
double rectangle_width
double total_area_of_property
double farmable_area_in_acres
double non_farmable_area_in_acres

******************************************************
End of file
If you're confused about how to call a function, read this tutorial page (and possibly the part 2 of it as well):
http://www.cplusplus.com/doc/tutorial/functions/
OK..I changed the code...am I calling the functions right?

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

// Headers and Other Technical Items

#include <iostream>
using namespace std;
#include "C:\\Dev-Cpp\\user_library\\udst_monitor.h"
#include "C:\\Dev-Cpp\\user_library\\udst_geo_area.h"

// Function Prototypes

void get_data(void);
void process_data(void);
void show_results(void);

// Variables

double  rectangle_length;
double  rectangle_width; 
double  total_area_of_property;
double  farmable_area_in_acres;
double  non_farmable_area_in_acres;
int     square_ft_acre; 


//******************************************************
// main
//******************************************************

int main(void)
  {
  get_data();
  process_data();
  show_results();

  return 0;
  }

//******************************************************
// get data
//******************************************************  
  
void get_data(void)
  {
  
  cout << "\nEnter the length of the property in feet --->: ";
  cin >> rectangle_length;
  cout << "\nEnter the width of the property in feet ---->: ";
  cin >> rectangle_width;

  
  return;
  }
  
//******************************************************
// process data
//******************************************************

void process_data(void)
  {




//******************************************************
// area_rectangle
//******************************************************

double area_rectangle (double rectangle_lenght, double rectangle_width) / 43560 ;


//******************************************************
// area_circle
//******************************************************

double area_circle (double radius) /43560 ;

 
  
 
//******************************************************
// non_farmable area
//******************************************************         
  
  non_farmable_area_in_acres = total_area_of_property - farmable_area_in_acres;               
                       
 
  return;
  }


//******************************************************
// show results
//******************************************************

void show_results(void)
  {
  
  cout << "\n";
  cout << "\nThe total area of the property in acres is ---->: ";
  cout << total_area_of_property;
  cout << "\nThe total farmable area in acres is -----> ";
  cout << farmable_area_in_acres;
  cout << "\nThe total non-farmable area in acres is -----> ";
  cout << non_farmable_area_in_acres;  


  pause_m();

  return;
  }



//******************************************************
// End of Program
//******************************************************







No, on lines 68 and 75 you make function declarations instead of function calls, and then try to divide them by 43560, which makes no sense. You need to call the functions, not declare or define them. Reread the tutorial.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//******************************************************
// area_rectangle
//******************************************************

area_rectangle = (double rectangle_length, double rectangle_width) / 43560 ;


//******************************************************
// area_circle
//******************************************************

 area_circle = (double radius) /43560 ;





????
Last edited on
Are you just guessing now?
No. I was being serious...

My understanding is that z= addition (5, 3); was the call example...unless my English is failing me again...?

I realized it should equal to the total area of rectangle and farmable area so I changed my code once again....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//******************************************************
// area_rectangle
//******************************************************

total_area_of_property = area_rectangle (double rectangle_length, double rectangle_width) / 43560 ;


//******************************************************
// area_circle
//******************************************************

farmable_area_in_acres = area_circle (double radius) /43560 ;
  
 
//******************************************************
// non_farmable area
//******************************************************         
  
  non_farmable_area_in_acres = total_area_of_property - farmable_area_in_acres;               
                       
 
  return;
  }
Last edited on
- You need to declare the variable total_area_of_property and the others
- You need to pass arguments to the function call, right now you are just copy-pasting the declaration.

Wrong:

variable = function(int x, int y);

Right:

int variable = function(5, 3);
Current 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
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

// Headers and Other Technical Items

#include <iostream>
using namespace std;
#include "C:\\Dev-Cpp\\user_library\\udst_monitor.h"
#include "C:\\Dev-Cpp\\user_library\\udst_geo_area.h"

// Function Prototypes

void get_data(void);
void process_data(void);
void show_results(void);

// Variables

double  rectangle_length;
double  rectangle_width; 
double  total_area_of_property;
double  farmable_area_in_acres;
double  non_farmable_area_in_acres;
int     square_ft_acre; 


//******************************************************
// main
//******************************************************

int main(void)
  {
  get_data();
  process_data();
  show_results();

  return 0;
  }

//******************************************************
// get data
//******************************************************  
  
void get_data(void)
  {
  
  cout << "\nEnter the length of the property in feet --->: ";
  cin >> rectangle_length;
  cout << "\nEnter the width of the property in feet ---->: ";
  cin >> rectangle_width;

  
  return;
  }
  
//******************************************************
// process data
//******************************************************

void process_data(void)
  {


//******************************************************
// area_rectangle
//******************************************************

double //should I keep the double part here? or not? because I don't get an error message if I take it out

total_area_of_property = area_rectangle (rectangle_length, rectangle_width) / 43560 ;


//******************************************************
// area_circle
//******************************************************


//Now if I keep the double in the area_rectangle or not, I get an error message in this line


double farmable_area_in_acres = area_circle (radius) / 43560 ;
  
 
//******************************************************
// non_farmable area
//******************************************************         
  
  non_farmable_area_in_acres = total_area_of_property - farmable_area_in_acres;               
                       
 
  return;
  }


//******************************************************
// show results
//******************************************************

void show_results(void)
  {
  
  cout << "\n";
  cout << "\nThe total area of the property in acres is ---->: ";
  cout << total_area_of_property;
  cout << "\nThe total farmable area in acres is -----> ";
  cout << farmable_area_in_acres;
  cout << "\nThe total non-farmable area in acres is -----> ";
  cout << non_farmable_area_in_acres;  


  pause_m();

  return;
  }



//******************************************************
// End of Program
//******************************************************











You get that error because you didn't define radius anywhere.

And whether or not you put double there for them depends on if you want to assign to the global variables or not. Don't put double if you want to assign to the global variables.
I thought I had defined it in the udst_geo_area? Can I change radius to rectangle_width /2 ?

The official pseudocode from my professor is: Call area_circle function passing the radius (which is 1/2 of the width)
My code works after making the change and I'm getting the values I'm suppose to get. Thanks for guiding me. I know it was frustrating.
Topic archived. No new replies allowed.