#include #include #include #include #include "cgi.h" using namespace std; int main() { cout << "Content-type: text/html\n\n" << "\n" << "\n" << "\n" << "Travelling...\n" << "\n" << "\n" << "\n" << "\n" << "

Calculate Your Weight on Different Planets

\n"; const cgi c; const map& m {c.get_input()}; double weight {0.0}; auto it {m.find("weight")}; if (it == end(m)) { cout << "
Could't get mass<\n"; } else if (it->second == "") { weight = 0.0; } else { weight = stod(it->second); } if (weight <= 0.0) { cout << "
Mass must be positive.\n"; } int planet {0}; auto itt {m.find("planet")}; if (itt == end(m)) { cout << "
Could not get planet. I don't remember putting Pluto here.\n"; } else { planet = stoi(itt->second); } struct body { string name; double gravity; }; const map aduetog { {"1", {"Mercury", 0.38}}, {"2", {"Venus", 0.91}}, {"3", {"Earth", 1.00}}, {"4", {"Mars", 0.38}}, {"5", {"Jupiter", 2.34}}, {"6", {"Saturn", 1.06}}, {"7", {"Uranus", 0.92}}, {"8", {"Neptune", 1.19}} }; auto itplanet = aduetog.find(to_string(planet)); //revert to look in struct body if (itplanet == end(aduetog)){ cout << "
Could not get planet in our current solar system.\n"; } else { double g = itplanet->second.gravity; string p = itplanet->second.name; double weightcalc = weight * g; cout << "
Your weight on " << p << " is " << weightcalc << " pounds.\n"; } cout << "\n" "\n"; return EXIT_SUCCESS; }