Bool error's help please.

having some issues with my bool. Any help would be nice.
any help would be nice I am trying to figure out at the same time just having a difficult time trying to get the bool to work with me. I know that is has something to do with planet[planetNum].distance, but I am not sure where to go with it. It looks right to me?
errors:
1 IntelliSense: identifier "planetNum" is undefined 28 23
2 IntelliSense: expected a ')' 28 33


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
/* Name: 
Assignment: 
Date Written: 
Course: 
Program:
Purpose: 
Sources: 
*/
#include <iostream>
#include <iomanip>

const int NSIZE = 256;
const int PSIZE = 20;

using namespace std;


struct planet {
	int currentPlanet;
	char name[NSIZE];
	double diameter;
	int distance; /*planet struct*/
	double avgTemp;
	char type[NSIZE]; 
	bool habitable;
};
bool habitable(planet[planetNum].distance >= 100 || planet[planetNum].distance <= 75 && planet[planetNum].type == terrestrial && planet[planetNum].diameter <= 10000 || planet[planetNum].diameter >= 5000 && planet[planetNum].avgTemp >= 45 || planet[planetNum].avetemp <= 75)
{
	if (habitable)
	{
		cout << "yes";
	}
	else {
		cout << "no";
	}
}

int main()
{
	int pN;
	int planetNum = 0; 
	char choice;
	int currentPlanet = 0;
	planet planet[PSIZE];
	

	do {
		cout << "**********************************";
		cout << "\n Welcome to the planet mapper" << endl << endl;
		cout << "Here are your following options." << endl;
		cout << "a. Add a planet" << endl;
		cout << "s. select a planet" << endl;				 /*Main Menu*/
		cout << "l. list all planets" << endl;
		cout << "q. To quit the program." << endl;
		cout << "Please use all lower case during the program" << endl;
		cout << "**********************************" << endl;
		cout << "please enter your choice: ";
		cin >> choice;
		cin.ignore(); // Added ignore, to get rid of '\n' stuck in the buffer.

		switch (choice) {
		case 'a':
		case 'A':
			if (currentPlanet < PSIZE)
			{
				cout << "Add a planet to the database." << endl;  /*Adding a planet*/
				cout << "\nPlease enter the name of the planet: ";
				cin.get(planet[currentPlanet].name, NSIZE);
				cout << "\nPlease enter the diamter of the planet: ";
				cin >> planet[currentPlanet].diameter;
				cout << "\nPlease enter the average tempature of the planet: ";
				cin >> planet[currentPlanet].avgTemp;
				cout << "\nPlease enter the planets distance from its star in millions of miles: ";
				cin >> planet[currentPlanet].distance;
				cin.ignore(); 
				cout << "Please enter the type of planet: ";
				cin.get(planet[currentPlanet].type, NSIZE);
				currentPlanet++;
				break;
			}
			else
				cout << "Sorry, no more room left in the system.";
			break;
		case 's':
		case 'S':
			if (currentPlanet > 0)
			{

				cout << "List a planet"; /* List certain planet #*/
				cout << "Please pick a planet number: " << endl;
				 cin >> currentPlanet; 
				 pN = currentPlanet;
				cin >> planetNum;
				if (planetNum <= currentPlanet) 
				{
					cout << "Planet number: " << planetNum << endl;
					cout << "Name: " << planet[planetNum].name << endl;
					cout << "Diameter: " << planet[planetNum].diameter << " " << "miles" << endl;
					cout << "Distance from star: " << planet[planetNum].distance << " " << "million miles" << endl;
					cout << "Average temperature: " << planet[planetNum].avgTemp << " " << "Degrees F" << endl;
					cout << "type: " << planet[planetNum].type << endl;
					cout << "habitable: " << planet[planetNum].habitable << endl; 
				}
				else
					cout << "Sorry, that planet is not part of the database." << endl;
				break;
			}
			else
				cout << "sorry no planets have been added in the database yet" << endl;
			break;
		case 'l':
		case 'L':
			if (currentPlanet > 0) {
				cout << "List the planets." << endl;
				for (int i = 0; i < currentPlanet; i++)    /*list all of the planets in the database*/
				{
					cout << "Planet number: " << i << endl; 
					cout << "Name: " << planet[i].name << endl;
					cout << "Diameter: " << planet[i].diameter << " " << "miles" << endl;
					cout << "Distance from star: " << planet[i].distance << " " << "million miles" << endl;
					cout << "Average temperature: " << planet[i].avgTemp << " " << "Degrees F" << endl;
					cout << "type: " << planet[i].type << endl;
					cout << "habitbale: " << planet[i].habitable << endl;
				}
			}
			else
				cout << "No planets have been added to the database" << endl;
			break;
		case 'q':
		case 'Q':
			cout << "Thank you for using Chad's planet database." << endl;
			cout << "Enjoy the rest of your day." << endl;
			system("pause");
			break;
		}
	} while (choice != 'q');
}
It's actually got something to do with how you wrote your entire function in line 27. That's not how a function head is written. You don't have any conditions in a parameter list, if it's supposed to take any.
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
bool habitable(const planet &planet)
{
	return
		planet.distance >= 100 || planet.distance <= 75
		&& planet.type == terrestrial
		&& planet.diameter <= 10000 || planet.diameter >= 5000
		&& planet.avgTemp >= 45 || planet.avetemp <= 75
}

//called like
cout << "habitbale: " << (habitable(planet[i])?"yes": "no") << endl;

//or as a member function
struct planet{
	//...
	bool habitable() const
	{
		return
			distance >= 100 || distance <= 75
			&& type == terrestrial
			&& diameter <= 10000 || diameter >= 5000
			&& avgTemp >= 45 || avetemp <= 75
	}
};
//called like
cout << "habitbale: " << (planet[i].habitable()?"yes": "no") << endl;
ne555 thank you man +1
ne555

went ahead and edited my code to
getting these error's though
1 IntelliSense: identifier "terrestrial" is undefined c 30 22
2 IntelliSense: expected a ';' 34 1
3 IntelliSense: identifier "i" is undefined 100 49
4 IntelliSense: expected a '}' 135 3

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
/* Name: 
Assignment: 
Date Written: 
Course: 
Program:
Purpose: to code a program to act as a planet map.
Sources: 
#include <iostream>
#include <iomanip>

const int NSIZE = 256;
const int PSIZE = 20;

using namespace std;


struct planet {
	int currentPlanet;
	char name[NSIZE];
	double diameter;
	int distance; /*planet struct*/
	double avgTemp;
	char type[NSIZE]; 
	bool habitable(const planet &planet)
	{
		return
			planet.distance >= 100 || planet.distance <= 75
			&& planet.type == terrestrial
			&& planet.diameter <= 10000 || planet.diameter >= 5000
			&& planet.avgTemp >= 45 || planet.avgTemp <= 75

};

int main()
{
	int pN;
	int planetNum = 0; 
	char choice;
	int currentPlanet = 0;
	planet planet[PSIZE];
	

	do {
		cout << "**********************************";
		cout << "\n Welcome to Chad's planet map" << endl << endl;
		cout << "Here are your following options." << endl;
		cout << "a. Add a planet" << endl;
		cout << "s. select a planet" << endl;				 /*Main Menu*/
		cout << "l. list all planets" << endl;
		cout << "q. To quit the program." << endl;
		cout << "Please use all lower case during the program" << endl;
		cout << "**********************************" << endl;
		cout << "please enter your choice: ";
		cin >> choice;
		cin.ignore(); // Added ignore, to get rid of '\n' stuck in the buffer.

		switch (choice) {
		case 'a':
		case 'A':
			if (currentPlanet < PSIZE)
			{
				cout << "Add a planet to the database." << endl;  /*Adding a planet*/
				cout << "\nPlease enter the name of the planet: ";
				cin.get(planet[currentPlanet].name, NSIZE);
				cout << "\nPlease enter the diamter of the planet: ";
				cin >> planet[currentPlanet].diameter;
				cout << "\nPlease enter the average tempature of the planet: ";
				cin >> planet[currentPlanet].avgTemp;
				cout << "\nPlease enter the planets distance from its star in millions of miles: ";
				cin >> planet[currentPlanet].distance;
				cin.ignore(); 
				cout << "Please enter the type of planet: ";
				cin.get(planet[currentPlanet].type, NSIZE);
				currentPlanet++;
				break;
			}
			else
				cout << "Sorry, no more room left in the system.";
			break;
		case 's':
		case 'S':
			if (currentPlanet > 0)
			{

				cout << "List a planet"; /* List certain planet #*/
				cout << "Please pick a planet number: " << endl;
				 cin >> currentPlanet; 
				 pN = currentPlanet;
				cin >> planetNum;
				if (planetNum <= currentPlanet) 
				{
					cout << "Planet number: " << planetNum << endl;
					cout << "Name: " << planet[planetNum].name << endl;
					cout << "Diameter: " << planet[planetNum].diameter << " " << "miles" << endl;
					cout << "Distance from star: " << planet[planetNum].distance << " " << "million miles" << endl;
					cout << "Average temperature: " << planet[planetNum].avgTemp << " " << "Degrees F" << endl;
					cout << "type: " << planet[planetNum].type << endl;
					cout << "habitbale: " << (habitable(planet[i]) ? "yes" : "no") << endl;
				}
				else
					cout << "Sorry, that planet is not part of the database." << endl;
				break;
			}
			else
				cout << "sorry no planets have been added in the database yet" << endl;
			break;
		case 'l':
		case 'L':
			if (currentPlanet > 0) {
				cout << "List the planets." << endl;
				for (int i = 0; i < currentPlanet; i++)    /*list all of the planets in the database*/
				{
					cout << "Planet number: " << i << endl; 
					cout << "Name: " << planet[i].name << endl;
					cout << "Diameter: " << planet[i].diameter << " " << "miles" << endl;
					cout << "Distance from star: " << planet[i].distance << " " << "million miles" << endl;
					cout << "Average temperature: " << planet[i].avgTemp << " " << "Degrees F" << endl;
					cout << "type: " << planet[i].type << endl;
					cout << "habitbale: " << (habitable(planet[i]) ? "yes" : "no") << endl;
				}
			}
			else
				cout << "No planets have been added to the database" << endl;
			break;
		case 'q':
		case 'Q':
			cout << "Thank you for using Chad's planet database." << endl;
			cout << "Enjoy the rest of your day." << endl;
			system("pause");
			break;
		}
	} while (choice != 'q');
}
Line 7: Missing a close comment (*/)

Line 24: ne555 gave you two examples. One as a stand-alone function and one as a member function. You're using the wrong example as a member function. Note that the member function does not take an argument.

1
2
3
4
5
6
7
8
// Member function
	bool habitable() const
	{  return
			distance >= 100 || distance <= 75
			&& type == terrestrial  // see comment below about this line
			&& diameter <= 10000 || diameter >= 5000
			&& avgTemp >= 45 || avetemp <= 75;
	}

Line 28: You're comparing type to terrestrial, but terrestrial is never defined. Since type is a char array, you should be using strcmp and compare a quoted string.
 
  && strcmp(type, "terrestrial") == 0

Better to use C++ std::string than C-style strings.

Line 30: Missing a ;

Line 31: Missing a }

Line 98,119: The correct way to use a member function:
 
cout << "habitbale: " << (planet[planetNum].habitable() ? "yes" : "no") << endl;


edit:
Lines 91-98 and 112-120 do exactly the same thing. You should create a member function to display information about a planet.
1
2
3
4
5
6
7
8
9
//  member function
   void Display () const
   {   cout << "Name: " << name << endl;
	cout << "Diameter: " << diameter << " " << "miles" << endl;
	cout << "Distance from star: " << distance << " " << "million miles" << endl;
       	cout << "Average temperature: " << avgTemp << " " << "Degrees F" << endl;
        cout << "type: " << type << endl;
        cout << "habitable: " << (habitable() ? "yes" : "no") << endl;
   }


Line 27: Don;t you have the following condition wrong?
 
planet.distance >= 100 || planet.distance <= 75

That states the planet must be more than 100M miles or less than 75M miles from the sun.
Shouldn;t the condition be:
 
distance >= 75 && distance <= 100

I'd suggest checking your other conditions also. diameter and avgTemp conditions are questionable.
Last edited on
Topic archived. No new replies allowed.