Having trouble pointing to a structure

Hello, I am sorry if this is such a simple fix, but I have a bad habit of making things harder for myself. I am having trouble with pointers and currently have a program that will not work for me. I get the errors on lines 40 and 41.
I am not sure where I am going wrong as this is the third or fourth way that I have tried to initialize my pointer. Any help is appreciated. Thanks!
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
/******************************************************************************************/
/*                                                                                        */
/*                             Programmer: Jason Smith                                    */
/*                                                                                        */
/*                           CSC 134 --> C++ Programming                                  */
/*                                                                                        */
/*                              non-Chapter Homework                                      */
/*                                                                                        */
/*                                    Program 4                                           */
/*                                                                                        */
/******************************************************************************************/

// Program Headers/Libraries
#include <iostream>
#include <cstdlib>
#include <string>
#include <math.h>

using namespace std;

struct building
{
	double length;
	double width;
	double height;
}unit;

////////// /* Function Prototypes */ //////////
double calc_area(double unit);
double num_wins(double &total);
double calc_BTU(double unit);

//////////////////// /* Main body of program */ ////////////////////
int main()
{
		
	//Variables Used in Program
	std::string name, grade;
	double coats, brush, gallon, grand, total, negative, window, BTU=0;
	double *ptr;
	building *ptr;
		
	//Obtain User Data
	cout<<"Welcome, Please enter your FIRST NAME: ";
	cin>>name;
	system("CLS"); //Clear Screen and start with new page.

	cout<<"Thank you "<<name<<".\n\n***** We are now ready for your buildings measurements. *****\n";
	cout<<"Please enter the length in feet. "; cin>>unit.length;
	cout<<"Please enter the width in feet. "; cin>>unit.width;
	cout<<"Please enter the height in feet. "; cin>>unit.height;
	cout<<"\n\n***** Now we need to know how many coats of paint will be applied. ******\n";
	cout<<"Please enter the number of coats that will be applied. "; cin>>coats;
	system("CLS"); // Clears screen for a new page again.

	//Calling Functions and Performing Other Calculations
	total = calc_area(*ptr);
	window = num_wins(total);
	BTU = calc_BTU(*ptr);
	negative = total-(window * 18);
	grand = negative*coats;
	brush = ceil(grand/1100);
	gallon = ceil(grand/325);
	
	//Determine the Cooling Unit Class.
	if (BTU > 0 && BTU < 14500)
	{
		grade = "A";
	}
	else if (BTU >= 14501 && BTU <= 29500)
	{
		grade = "B";
	}
	else if (BTU >= 29501 && BTU <= 45000)
	{
		grade = "C";
	}
	else if (BTU >= 45001 && BTU <= 61000)
	{
		grade = "D";
	}
	else if (BTU >= 61001 && BTU <= 75000)
	{
		grade = "E";
	}
	else if (BTU >= 75001 && BTU <= 100000)
	{
		grade = "F";
	}
	else if (BTU >= 100001)
	{
		grade = "G";
	}
	
	//Display all results to User.
	cout<<"Thank you "<<name<<". Here is your list of supplies.\n\n";
	cout<<"Total surface area: "<<negative<<"sqft"<<endl;
	cout<<"Number of coats: "<<coats<<endl;
	cout<<"Number of brushes required: "<<brush<<endl;
	cout<<"Gallons of paint required: "<<gallon<<endl;
	cout<<"Number of windows needed: "<<window<<endl;
	cout<<"The BTUs required to cool the unit are: "<<BTU<<endl;
	cout<<"Your recommended Cooling Unit is Grade "<<grade<<"."<<endl;
	cout<<endl;
	system("PAUSE");
	return 0;
}



//////////////////// /* Function for calculating surface area. */ ////////////////////
double calc_area(double building)
{
	double wall1, wall2, wall3, wall4, total;

	wall1 = unit.length*unit.height;
	wall2 = unit.length*unit.height;
	wall3 = unit.width*unit.height;
	wall4 = unit.width*unit.height;
	total = wall1+wall2+wall3+wall4;
	return total; //return variable 'total'
}



//////////////////// /* Function for calculating number of windows. */ ////////////////////
double num_wins(double &total)
{
	double window;
	window = ceil(total/150);
		if ((int)(window) %2==0) // Cast double as int to check for mod 2 remainder of zero and if a remainder is present, it will add 1 to window.
		{	
			window = window;
		}
		else
		{	
			window++;
		}
	return window; //return variable 'window'
}



//////////////////// /* Function for calculating number of BTUs. */ ////////////////////
double calc_BTU(double building)
{
	double cubicArea, BTU;
	cubicArea = (unit.length * unit.height * unit.width);
	BTU = cubicArea/1000;
	return BTU;
}
You may not define the same name for several objects in the same declarative region

1
2
	double *ptr;
	building *ptr;
.
Last edited on
Thank you for the quick reply... I'm not entirely sure what you mean but it gives me a good base on which to start. Just need to do some more research and studying. :)
The both declarations declare the same name for objects of different types. So the compiler does not know how to consider name ptr either as a pointer to double or a pointer to building.
Thanks vlad from moscow --> you helped me to find the answer on my own and helped me learn the accurate way to declare pointers.

building *ptr = new building;
This line replaced the two lines (40,41) and fixed my pointer issues.

I now get issues with:

Prog4-JS.obj : error LNK2019: unresolved external symbol "double __cdecl calc_BTU(struct building)" (?calc_BTU@@YANUbuilding@@@Z) referenced in function _main

Been searching for an answer to what exactly this means but have not been able to find one so far. This is my edited code if you're interested:

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
/******************************************************************************************/
/*                                                                                        */
/*                             Programmer: Jason Smith                                    */
/*                                                                                        */
/*                           CSC 134 --> C++ Programming                                  */
/*                                                                                        */
/*                              non-Chapter Homework                                      */
/*                                                                                        */
/*                                    Program 4                                           */
/*                                                                                        */
/******************************************************************************************/

// Program Headers/Libraries
#include <iostream>
#include <cstdlib>
#include <string>
#include <math.h>
using namespace std;
/*******************************************************************************************************************************************************/
struct building
{
	double length;
	double width;
	double height;
}unit;
/*******************************************************************************************************************************************************/
////////// /* Function Prototypes */ //////////
double calc_area(building);
double num_wins(double &total);
double calc_BTU(building);
/*******************************************************************************************************************************************************/
//////////////////// /* Main body of program */ ////////////////////
int main()
{
		
	//Variables Used in Program
	std::string name, grade;
	double coats, brush, gallon, grand, total, negative, window, BTU=0;
	building *ptr = new building;
		
	//Obtain User Data
	cout<<"Welcome, Please enter your FIRST NAME: ";
	cin>>name;
	system("CLS"); //Clear Screen and start with new page.
	
	cout<<"Thank you "<<name<<".\n\n***** We are now ready for your buildings measurements. *****\n";
	cout<<"Please enter the length in feet. "; cin>>unit.length;
	cout<<"Please enter the width in feet. "; cin>>unit.width;
	cout<<"Please enter the height in feet. "; cin>>unit.height;
	cout<<"\n\n***** Now we need to know how many coats of paint will be applied. ******\n";
	cout<<"Please enter the number of coats that will be applied. "; cin>>coats;
	system("CLS"); // Clears screen for a new page again.

	//Calling Functions and Performing Other Calculations
	total = calc_area(unit);
	window = num_wins(total);
	BTU = calc_BTU(unit);
	negative = total-(window * 18);
	grand = negative*coats;
	brush = ceil(grand/1100);
	gallon = ceil(grand/325);
	
	//Determine the Cooling Unit Class.
	if (BTU > 0 && BTU < 14500)
	{
		grade = "A";
	}
	else if (BTU >= 14501 && BTU <= 29500)
	{
		grade = "B";
	}
	else if (BTU >= 29501 && BTU <= 45000)
	{
		grade = "C";
	}
	else if (BTU >= 45001 && BTU <= 61000)
	{
		grade = "D";
	}
	else if (BTU >= 61001 && BTU <= 75000)
	{
		grade = "E";
	}
	else if (BTU >= 75001 && BTU <= 100000)
	{
		grade = "F";
	}
	else if (BTU >= 100001)
	{
		grade = "G";
	}
	
	//Display all results to User.
	cout<<"Thank you "<<name<<". Here is your list of supplies.\n\n";
	cout<<"Total surface area: "<<negative<<"sqft"<<endl;
	cout<<"Number of coats: "<<coats<<endl;
	cout<<"Number of brushes required: "<<brush<<endl;
	cout<<"Gallons of paint required: "<<gallon<<endl;
	cout<<"Number of windows needed: "<<window<<endl;
	cout<<"The BTUs required to cool the unit are: "<<BTU<<endl;
	cout<<"Your recommended Cooling Unit is Grade "<<grade<<"."<<endl;
	cout<<endl;
	system("PAUSE");
	return 0;
}
/*******************************************************************************************************************************************************/
//////////////////// /* Function for calculating surface area. */ ////////////////////
double calc_area(double *ptr)
{
	double wall1, wall2, wall3, wall4, total1;

	wall1 = unit.length*unit.height;
	wall2 = unit.length*unit.height;
	wall3 = unit.width*unit.height;
	wall4 = unit.width*unit.height;
	total1 = wall1+wall2+wall3+wall4;
	return total1; //return variable 'total'
}
/*******************************************************************************************************************************************************/
//////////////////// /* Function for calculating number of windows. */ ////////////////////
double num_wins(double &total)
{
	double window=0;
	window = ceil(total/150);
		if ((int)(window) %2==0) // Cast double as int to check for mod 2 remainder of zero and if a remainder is present, it will add 1 to window.
		{	
			window = window;
		}
		else
		{	
			window++;
		}
	return window; //return variable 'window'
}
/*******************************************************************************************************************************************************/
//////////////////// /* Function for calculating number of BTUs. */ ////////////////////
double calc_BTU(double *ptr)
{
	double cubicArea, code;
	cubicArea = (unit.length * unit.height * unit.width);
	code = cubicArea/1000;
	return code;
}
Last edited on
NVM all... I just ended up removing the pointers and the program works.
I do not have to involve pointers but wanted to just so I could learn them get used to using them.

Thanks for all the help. I will definitely continue to use this forum for my future learning needs. :)
You declared function calc_BTU as

double calc_BTU(building);

but defined it as

double calc_BTU(double *ptr)


So when you call it as

BTU = calc_BTU(unit);

where unit has type building the compiler does not find its definition.



Topic archived. No new replies allowed.