Question about static_cast


I would like to insert a static_cast code into my program so that when the weight of each person is calculated, that it will round up each number. I realize that the program alread does round up with setprecision. But I would like to see if I could do it with set_cast. Any suggested code and help would be very beneficial. Please Help...
/******************************************************************************

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.
First it will ask you how old you are and then your weight. It will tell you
what you inputed, then it will calculate the amount of years and decades you've
been around for. Then with the weight you inputed earlier it will calculate
your weight with each of the given constants for the Moon, Mars and the Sun.
These weights are calculated by multiplying them by your weight on Earth.
After the questioning process is over, your information will be
exported to an external file, Weight,proj2.txt.
With all this said we shall begin...
******************************************************************************/

#include<iostream>
#include<fstream> //used to create an external file
#include<iomanip> //needed to use these stream manipulators
#include<cstdlib>
using namespace std;

int main()
{

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
string name_of_user;
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
int num_age_with_Years;
double user_Weight, user_weight_Moon;
double user_weight_Sun;
int val;
int temp;



double user_weight_Mars;
ofstream outs;










//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 first calculate the user's age according to the amount\n"
<<"of years and decades you have been around for. Next, using the given numeric\n"
<<"constants which define a value in which you must multiple your weight on\n"
<<"Earth times the given constant of each planet. With those constants you can\n"
<<"calculate your weight on the Moon, Mars, and the Sun. After all of these\n"
<<" laborious tasks have been completed, your answers will be exported into the\n"
<<"external file, Weight,proj2.txt. You will then be able to access this info\n"
<<"from the newly created .txt file as well as append any errors. With all this\n"
<<"said, we shall bein...\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(lbs)

cout<<"Please enter your weight[lbs]:\n";
cin>>user_Weight;



//Say hello to the user, reassure them of what answers they have inputed.

outs.open("Weight,proj2.txt",ios::app);

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";

//The "outs" indicates the information that will be inputed into the external
//file, Weight,proj2.txt

outs<<"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";

//Compute the users age in decades and years by using the common function below,
//Decades/user_Age. Note the different usage of the division symbol


num_age_with_Decade = user_Age / 10 ;
num_age_with_Years = user_Age % 10 ;

//Explain to the user the years and decade the user has been around for, based
//on the common notion that 10 years is equivalent to one decade.

cout <<"Did you know that you are, "<< num_age_with_Decade <<" decades and "<< num_age_with_Years <<endl;
cout<<"year's old?\n\n";

outs <<"Did you know that you are, "<< num_age_with_Decade <<" decades and "<< num_age_with_Years <<endl;
outs<<"year's old?\n\n";

//Using the Moon constant, calculate the users weight by multiplying your weight
//on Earth by 0.165306. Setprecision(4), allows only four digits to be displayed
//in the answer.

cout<<setprecision(4);
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";

user_weight_Moon = user_Weight*calc_Moon;
outs<<setprecision(4);
outs<<"Did you know your weight on the Moon would be about "<<user_weight_Moon<<"\n"
"pounds?\n\n";

//Using the Mars constant(0.38137), multiply that by your weight on Earth

user_weight_Mars= user_Weight*calc_Mars;
cout<<"Did you know that you weigh about "<<user_weight_Mars<<" pounds \n"
"on Mars?\n\n";

user_weight_Mars= user_Weight*calc_Mars;
outs<<"Did you know that you weigh about "<<user_weight_Mars<<" pounds \n"
"on Mars?\n\n";

//Using the Suns constant(27.96788), multiply that by your weight on Earth.
//Setprecision(5) allows 5 digits to be displayed in the answer
cout<<setprecision(4);
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";

//Thank the user for participating in this program of pure drudgery.

cout<<"Thank you for participating in this trivia game...\n\n\n\n";

outs<<setprecision(4);
user_weight_Sun= user_Weight*calc_Sun;
outs<<"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";

outs<<"Thank you for participating in this trivia game...\n\n\n\n";


outs.close();


system("PAUSE");
return 0;
}
Use round() instead of a cast.

 
double round( double x );


rounds x to the nearest integer. 0.5 is rounded to 1.0, -0.5 is rounded to -1.0.
Topic archived. No new replies allowed.