#include #include #include using namespace std; struct planetacc { string body; double gravity; }; void convert(double& weightlb, double& weightkg, double gravity) { weightkg = (weightlb * 0.45359237) / 9.8 * gravity; } int main (){ cout << "Type in a planet to know the weight of something over there.\n"; string pick; cin >> pick; static const planetacc aduetog[]{ {"earth", 9.81}, {"mercury", 3.7}, {"venus", 8.87}, {"mars", 3.71}, {"jupiter",24.79}, {"saturn", 10.44}, {"uranus", 8.69}, {"neptune", 11.15} }; static const int a {size(aduetog)}; int planetpick = -1; for (int i {0}; i < a; i++) { if (pick == aduetog[i].body) { planetpick = i; break; } } if (planetpick == -1) { cerr << "We couldn't find that planet here.\n"; return EXIT_FAILURE; } cout << "Type in the weight in pounds.\n"; double weightlb{0}; cin >> weightlb; if (weightlb < 0) { cerr << "Lets not go lower than 0.\n"; return EXIT_FAILURE; } double weightkg {0}; convert(weightlb, weightkg, aduetog[planetpick].gravity); cout << "This weighs " << weightkg << " kg on " << pick << "\n"; return EXIT_SUCCESS; }