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
|
#include <string>
#include <set>
#include <vector>
#include <functional>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include<valarray>
#include<fstream>
using namespace std;
enum planetType {Mercury, Venus, Earth, Moon, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto, PlanetMax};
const double gravities [PlanetMax] = {0.4155, 0.8975, 1.0, 0.166, 0.3507, 2.5374, 1.0677, 0.8947, 1.1794, 0.0899};
const string planetName[PlanetMax] = {"Mercury", "Venus", "Earth", "Moon", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"};
//double calcWeight(planetType, double); //TBD?
planetType findPlanetName(string &str)
{
for(int i = Mercury; i < PlanetMax; i++)
if(str == planetName[i]) return (planetType)i;
return PlanetMax; //default
}
//void GetUserInput(double &UserWeight, string &InputPlanet); //TBD?
int main()
{
double weight = 0.0;
string repeat;
string planetIn;
// Prompt user to enter his/her weight and the name of a planet
//cout << "Your Name!"<<endl;
//cout <<""<<endl;
while(true)
{
cout << "We are going to determine your weight on another planet!"<<endl;
cout << "You don't have to be honest :)"<<endl;
cout << " "<<endl;
cout << "Please Enter Weight: ";
cin >> weight;
cout<< ""<<endl;
cout << "Enter name of planet exactly as shown!" << endl;
cout << " "<<endl;
cout << "Mercury, Venus, Earth, Moon, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto" << endl;
cout <<""<<endl;
std::cout << "Enter planet name here: ";
cin >> planetIn;
planetType planet = findPlanetName(planetIn);
switch(planet)
{
case Mercury:
case Venus:
case Earth:
case Moon:
case Mars:
case Jupiter:
case Saturn:
case Uranus:
case Neptune:
case Pluto:
cout<<"If you currently weigh "<<weight<<" pounds,"<<endl;
cout<<"then you would weigh "<<weight * gravities [planet]<<" "<<" pounds on " << planetName[planet] << "!"<<endl;
break;
default:
cout << "Not in our Galaxy. Please check the spelling and try again." << endl;
cout << "Please enter, Mercury, Venus, Earth, Moon, Mars, Jupiter, Saturn, Neptune, or Pluto";
}
}
}
|