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
|
/* planet
*/
//planet.cpp – displays a grade based on the total number of points
//entered by the user
#include <iostream>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main()
{
//declare variables and arrays
double otherWeight = 0.0;
double weight = 0.0;
string name = " ";
string planet[9] = {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"};
double relGrav[9] = {0.4155, 0.8975, 1.0, 0.3507, 2.537, 1.0677, 0.8947, 1.1794, 0.5};
string statement[9] = {"M", "V", "E", "Ma", "J", "S", "U", "N", "P"};
char anotherName = ' ';
int x = 0;
char anotherPlanet = ' ';
//get input
cout << "This program calculates your weight on nine planets:" << endl;
cout << "1 Mercury" << endl;
cout << "2 Venus" << endl;
cout << "3 Earth" << endl;
cout << "4 Mars" << endl;
cout << "5 Jupiter" << endl;
cout << "6 Saturn" << endl;
cout << "7 Uranus" << endl;
cout << "8 Neptune" << endl;
cout << "9 Pluto" << endl;
do
{
cout << "Enter your name: ";
//added
cin.clear();
cin.sync();
getline(cin, name);
cout << "Enter weight: ";
cin >> weight;
do
{
cout << "Enter planet number (1-9): ";
cin >> x;
otherWeight = relGrav[x - 1] * weight;
cout <<name <<" Your weight on " << planet[x - 1] << " is: " << otherWeight<<endl ;
cout << statement[x - 1] << endl;
cout << "Do you want to enter another planet? (Y/N): ";
cin >> anotherPlanet;
anotherName = toupper(anotherPlanet);
} while (anotherPlanet != 'N');
cout << "Do you want to switch user? (Y/N): ";
cin >> anotherName;
anotherName = toupper(anotherName);
} while (anotherName != 'N');
return 0;
}
|