Comparing two Things

this is the program so Far,i am supposed to compare mars to Venus and Saturn to mercury,Earth to Jupiter.I am lost in that respect as the output shows 0,0,1

Thanks for your help

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
  //kelvin Njuguna
//Planet Assignment

#include <iostream>
#include <string>
using namespace std;


class Planet
{
	string name;
	char initial;
	double gravity;
	int orbit;

public:
	Planet(){
		name = "earth";
		initial = 'E';
		gravity = 9.78;
		orbit = 360;
	}
	
	

	
	Planet(string p, char i, double g, int o)
	{
		name = p;
		initial = i;
		gravity = g;
		orbit = o;
	}
	void setPlanetValues (string p, char i, double g, int o)
	{
		name = p;
		initial = i;
		gravity = g;
		orbit = o;
	}

void getPlanetValues  (string p, char& i, double& g, int& o)
{
	
		p = name;
		i = initial;
		g = gravity;
		o = orbit;
}
void printPlanet() const{
	cout <<"Planet:" << name <<endl;
	cout <<"Initial:"<< initial <<endl;
	cout <<"Gravity:"<< gravity <<endl;
	cout<<"Orbit:" << orbit << endl;
}


bool comparePlanet( Planet& otherPlanet) const {
	if(orbit < otherPlanet.orbit)
			return true;
		else return false;
			
}
};



int main (void)
{
	Planet Earth,Mercury("Mercury" , 'M', 3.72, 88),Venus("Venus", 'V', 8.80, 225),Mars("Mars", 'R', 3.71, 690),Jupiter("Jupiter", 'J', 23.1, 4332),Saturn("Saturn", 'S', 9.0, 10752),  Uranus("Uranus",'U',8.7, 30684), Neptune("Neptune", 'N', 11.0, 60190);
	
	Earth.printPlanet();
	Mercury.printPlanet();
	Venus.printPlanet();
	Mars.printPlanet();
	Jupiter.printPlanet();
	Saturn.printPlanet();
	Uranus.printPlanet();
	Neptune.printPlanet();

	bool a = Mars.comparePlanet(Venus);
	bool b = Saturn.comparePlanet(Mercury);
	bool c = Earth.comparePlanet(Jupiter);

	cout << a << endl;
	cout << b << endl;
	cout << c << endl;

system("pause");
return 0;
}
You can display "true" and "false" by using the boolalpha manipulator:

 
cout << boolalpha << a << endl;


Your output seems correct:

false
false
true
The function comparePlanet returns a boolean (true or false) result. By default this is output as either 1 or 0 to represent true or false.
Oh ok that makes sense @Daleth and @Chervil.Thank you very much for your help..This will become my go to for Help.
Topic archived. No new replies allowed.