Nov 18, 2013 at 1:18am UTC
This is the features that needed to be added to program
1. Ok now take what you’ve written for Part I and add a menu for the user. It should include all the info for each planet. Also validate the menu input.
2. Add a loop (you pick which one) to ask the user to run the program again. This should also include validating the input.
3. Now write all of the output to a text file.
The code below is what I have so far, but it's not performing any of the things that's being asked above. If you could please help me figure out what's wrong I would greatly appreciate it.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string name, planet;
double weight, speed;
double new_weight, planet_dist;
double s_gravity;
double trav_time;
char repeat;
ofstream outfile("output.txt");
do
{
cout <<"Enter your name:";
cin >> name;
cout << "Enter your weight on earth (in pounds):";
cin >> weight;
cout << "Enter the speed you wishes to travel (in miles per hour):";
cin >> speed;
cout << "Enter the planet you wishes to visit (FULLY CAPITAL LETTERS) :"<<endl;
cout<<"A menu will be supplied below\n";
cout<<"1.Mercury\n";
cout<<"2.Venus\n";
cout<<"3.Earth\n";
cout<<"4.Mars\n";
cout<<"5.Jupiter\n";
cout<<"6.Saturn\n";
cout<<"7.Uranus\n";
cout<<"8.Neptune\n";
cin >> planet;
while(planet.compare("MERCURY") &&
planet.compare("VENUS") &&
planet.compare("EARTH") &&
planet.compare("MARS") &&
planet.compare("JUPITER") &&
planet.compare("SATURN") &&
planet.compare("URANUS") &&
planet.compare("NEPTUNE"))
{
cout <<"Invalid Planet selected. Re-select your planet :";
cin >> planet;
cout << endl;
}
if(planet == "MERCURY")
{
s_gravity = 0.27;
planet_dist = 36;
}
if(planet == "VENUS")
{
s_gravity = 0.086;
planet_dist = 67;
}
if(planet == "EARTH")
{
s_gravity = 1.00;
planet_dist = 93;
}
if(planet == "MARS")
{
s_gravity = 0.37;
planet_dist = 141;
}
if(planet == "JUPITER")
{
s_gravity = 2.64;
planet_dist = 483;
}
if(planet == "SATURN")
{
s_gravity = 1.17;
planet_dist = 886;
}
if(planet == "URANUS")
{
s_gravity = 0.092;
planet_dist = 1782;
}
if(planet == "NEPTUNE")
{
s_gravity = 1.44;
planet_dist = 2793;
}
new_weight = weight * s_gravity;
trav_time = (planet_dist / speed);
cout << "\n------------------------------------\n";
cout << "\nName : " << name;
cout << "\nWeight on earth : " << weight;
cout << "\nPlanet destination : " << planet;
cout << "\nWeight on planet : " << new_weight;
cout << "\nTravel time from earth : " << trav_time << endl;
outfile << "\n------------------------------------\n";
outfile << "\nName : " << name;
outfile << "\nWeight on earth : " << weight;
outfile << "\nPlanet destination : " << planet;
outfile << "\nWeight on planet : " << new_weight;
outfile << "\nTravel time from earth : " << trav_time << endl;
cout << "Do you want to continue (y for yes n for no) ";
cin >> repeat;
cout << endl;
while(repeat!='y' && repeat!='Y' && repeat!='n' && repeat!='N')
{
cout << "Invalid Input. Do you want to continue ";
cin >> repeat;
cout << endl;
}
}while(repeat=='y' || repeat == 'Y');
outfile.close();
//system("pause");
}