Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Include statements
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- //Global declarations: Constants and type definitions only -- no variables
- enum PlanetType { MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE, PLUTO };
- //Function prototypes
- bool ValidPlanet(string userInput, PlanetType& planet);
- int main()
- {
- //In cout statement below substitute your name and lab number
- cout << "Christopher Kheir -- Lab 8" << endl << endl;
- //I have read and understand the Lab Submittal Policy on BB.
- //Variable declarations
- float userWeight;
- string userInput;
- PlanetType planet;
- //Program logic
- cout << "Please enter your weight: ";
- cin >> userWeight;
- cout << endl;
- do
- {
- cout << "Please enter a valid planet name from the list as shown. MERCURY , VENUS , EARTH , MARS , JUPITER , SATURN , URANUS , NEPTUNE , PLUTO : ";
- cin>>userInput;
- planet = EARTH;
- } while (!ValidPlanet(userInput,planet));
- //Closing program statements
- return 0;
- }
- bool ValidPlanet(string userInput, PlanetType& planet)
- {
- if(userInput == "MERCURY")
- {
- planet = MERCURY;
- return true;
- }
- else if(userInput == "VENUS")
- {
- planet = VENUS;
- return true;
- }
- else if(userInput == "EARTH")
- {
- planet = EARTH;
- return true;
- }
- else if(userInput == "MARS")
- {
- planet = MARS;
- return true;
- }
- else if(userInput == "JUPITER")
- {
- planet = JUPITER;
- return true;
- }
- else if(userInput == "SATURN")
- {
- planet = SATURN;
- return true;
- }
- else if(userInput == "URANUS")
- {
- planet = URANUS;
- return true;
- }
- else if(userInput == "NEPTUNE")
- {
- planet = NEPTUNE;
- return true;
- }
- else if(userInput == "PLUTO")
- {
- planet = PLUTO;
- return true;
- }
- else
- {
- cout<<"Error: invalid entry"<<endl;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement