This program will ask a series of questions relative to your age, weight, and
will quantify the correct weight when living on the Moon, Mars and the Sun.
When imputing your age it will calculate the amount of decades you have been
around for, you don't have to input your actual age if you are feel so inclined
not to do so. After the questioning porcess is over, your information will be
exported to an external file. With all this said we shall begin to poke and prod
questions at you...
******************************************************************************/
#include<iostream>
#include<fstream>
#include<iomanip> //needed to use these stream manipulators
#include<cstdlib>
using namespace std;
int main()
{
int num_Decade;
num_Decade = 10; //One decade is equivalent to ten years
int user_Age; //Enter the age of the user
int num_age_with_Decade; //The users age divided by one decade
double user_Weight, user_weight_Sun, user_weight_Moon, user_weight_Mars;
ofstream outs;
int num_age_with_Years;
string name_of_user;
const double calc_Moon = 0.165306; //The weight of a person on Moon is
//the Earth weight times the Moon constant
const double calc_Mars = 0.38137; //The weight on Mars equals Earth weight
//times the Mars constant
const double calc_Sun = 27.96788; //Weight on Sun euals the Earth weight
//times the Sun constant
//Describe the Program that the user will begin to use
cout<<"This program will ask a series of trivia questions relative to your age &\n"
<<"weight. It will then calculate the user's approximate weight when living\n"
<<"on the Moon, Mars and the Sun(Even though you may live for a few\n"
<<"seconds). When the user input's he/she's age it will calculate the\n"
<<"amount of decades you've been around for. Do not worry, the user can lie\n"
<<"about his/her age and weight if they feel so inclined. Later this\n"
<<"information will be exported to an external file. It will be put in a\n"
<<"small informative paragraph describing your weight on certain planets.\n"
<<"With all this said we shall begin...\n\n";
//Get user's name
cout<<"Enter your name:\n";
getline( cin, name_of_user);
//Get user's age
cout<<"Enter your age please:\n";
cin>>user_Age;
//Get users weight
cout<<"Please enter your weight:\n";
cin>>user_Weight;
//Say hello to the user, tell them their age and weight that they have inputed
cout<<"Hello, " << name_of_user <<"!\n"
<<"So you are "<< user_Age <<" years old!\n"
<<"So you weigh an astounding "<< user_Weight<<" pounds!\n\n\n\n";
//Explain to the user the years and decade the user has been around for
cout <<"Did you know that you are, "<< num_age_with_Decade <<" decades and "<< num_age_with_Years <<endl;
cout<<"year's old?\n\n";
//Calculate the user's weight on the Moon
user_weight_Moon = user_Weight*calc_Moon;
cout<<"Did you know your weight on the Moon would be about "<<user_weight_Moon<<"\n"
"pounds?\n\n";
//Calculate the users weight on Mars
user_weight_Mars= user_Weight*calc_Mars;
cout<<"Did you know that you weigh about "<<user_weight_Mars<<" pounds \n"
"on Mars?\n\n";
//Calculate the users weight on the Sun
user_weight_Sun= user_Weight*calc_Sun;
cout<<"Did you that you would weigh about "<<user_weight_Sun<<" pounds on the\n"
"Sun until you were vaporized into small particles of matter?...\n\n\n";
cout<<"Thank you for participating in this trivia game...\n\n\n\n";
//Open external file Weight,proj2.txt for writing and appending results.
outs.open("Weight,proj2.txt",ios::app);
//Send results to "Weight,proj2.txt" in tabular format.
outs<<endl<<endl<<endl;
//Set format for displaying the trivia questions to this application
//"Weight,proj2.txt".
You are saving to that file only endline characters:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//...
//Open external file Weight,proj2.txt for writing and appending results.
outs.open("Weight,proj2.txt",ios::app);
//Send results to "Weight,proj2.txt" in tabular format.
outs<<endl<<endl<<endl;
//Set format for displaying the trivia questions to this application
//"Weight,proj2.txt".
outs.close();
//...
After this the content of your file would be three empty lines
Yes I see that, so any suggestions on how I might be able to fix this coding error. I would like the file to have the information like what my weight would be on a certain planet to be exported into the new .txt file, not three blank lines.