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
|
#include<iomanip>
#include<iostream>
#include<string>
#include<algorithm>
int main()
{
const int N = 8 ;
const std::string planet[N] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" };
const double gravity[N] = { 0.37, 0.78, 1.00, 0.38, 2.64, 1.16, 1.07, 1.21 };
const std::string descr[N] =
{
"the smallest planet in the solar system",
"sometimes referred to as the 'Morning Star'",
"... what ever for earth ...",
"... what ever for mars ...",
"... what ever 4 ...",
"... what ever 5 ...",
"... what ever 6 ...",
"... what ever 7 ..."
};
double weight = 0.0;
while( std::cout << "\nPlease enter your weight on the great planet Earth\n(enter a negative weight "
"or non-numeric input eg. \"exit\" to end program): " &&
std::cin >> weight && weight >= 0 )
{
std::cout << "\nLets see now, which planet would you like to convert your weight to?\n" ;
for( auto& name : planet ) std::cout << name << ' ' ;
std::cout << "\nEnter planet name: ";
std::string planet_name ;
std::cin >> planet_name ;
// make first letter upper case, everything else lower case
for( char& c : planet_name ) c = std::tolower(c) ;
planet_name.front() = std::toupper( planet_name.front() ) ;
// locate the planet number
const int planet_num = std::find( planet, planet+N, planet_name ) - planet ;
if( planet_num == N )
std::cout << "Oh no! It seems like the planet name you entered is incorrect :(\n" ;
else
{
std::cout << "\nyour weight on " << planet_name << ", " << descr[planet_num]
<< ", is " << gravity[planet_num] * weight << '\n' ;
}
}//end of while loop
}//end of main functio
|