#include <iostream> using namespace std; //The following declares a new type called "planet" which can take *only* the //values in the list. enum planet {MERCURY,VENUS,EARTH,MARS,JUPITER,SATURN,URANUS,NEPTUNE}; //Try swapping in this line instead and see how the output changes. //enum planet {MERCURY,VENUS,EARTH,MARS = 10,JUPITER,SATURN,URANUS,NEPTUNE}; //This is a function prototype. Remember, either the prototype or the full //definition must appear before it can be used. //This function takes an argument of the type "planet", which we just //defined. float AccelerationDueToGravity(planet); main() { //See above note on line 8. Note that each item in the enum list has an //associated numerical value. cout << "MERCURY is " << MERCURY << endl; cout << "VENUS is " << VENUS << endl; cout << "EARTH is " << EARTH << endl; cout << "MARS is " << MARS << endl; cout << "JUPITER is " << JUPITER << endl; cout << "SATURN is " << SATURN << endl; cout << "URANUS is " << URANUS << endl; cout << "NEPTUNE is " << NEPTUNE << endl; planet our_planet = EARTH; //Try doing the following. Why doesn't it compile? // planet our_planet = PLUTO; cout << "Acceleration due to gravity is "; cout << AccelerationDueToGravity(our_planet) << " m/s^2" << endl; } float AccelerationDueToGravity(planet this_planet) { //Switch statements can also accept an enum variable as an argument. switch(this_planet) { case MERCURY: return 3.59; case VENUS: return 8.87; case EARTH: return 9.81; case MARS: return 3.77; case JUPITER: return 25.95; case SATURN: return 11.08; case URANUS: return 10.67; case NEPTUNE: return 14.07; } }