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, MOON, 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));
- switch (planet)
- {
- case MERCURY:
- cout << userWeight * 0.4155 << endl;
- break;
- case VENUS:
- cout << userWeight * 0.8975 << endl;
- break;
- case EARTH:
- cout << userWeight * 1.0 << endl;
- break;
- case MOON:
- cout << userWeight * 0.166 << endl;
- break;
- case MARS:
- cout << userWeight * 0.3507 << endl;
- break;
- case JUPITER:
- cout << userWeight * 2.5374 << endl;
- break;
- case SATURN:
- cout << userWeight * 1.0677 << endl;
- break;
- case URANUS:
- cout << userWeight * 0.8947 << endl;
- break;
- case NEPTUNE:
- cout << userWeight * 1.1794 << endl;
- break;
- case PLUTO:
- cout << userWeight * 0.0899 << endl;
- break;
- default:
- break;
- }
- //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 == "MOON")
- {
- planet = MOON;
- 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