Using static_cast and setw()

closed account (2EURX9L8)
I am making a report for a class in c++ and I am stuck
I cant seem to get it to display a calculation in double form, here is the code

int speed1=static_cast<double>(DISTANCE1/point1time)*MININHOUR, //Calculation for MPH in between checkpoints

The distance1 is 44 then the user inputs the point 1 time then times that by minutes in an hour=60 to get the MPH. There is an example our teacher gave us that has a point 1 time as 177 and the output is 22.564

my program just outputs a 0

I am also having trouble having info displayed and lining it up.
here is an example of my code
cout<<"\n\t\tInterval Details\n"<<endl;
cout<<"\tLocation "<<"Distance "<<"Time "<<"Speed\n";

cout<<setw(10)<<setfill('.')<<"Interval 1"<<setw(10)<<intervaldis1<<setw(5)<<time1<<setw(5)<<setprecision(5)<<speed1<<endl;

any advise?
I bet you declared both DISTANCE1 and point1time as integers. Integer division rounds down, that is, 1/2=0. If you only did the cast on DISTANCE1, it would all be okay.
Topic archived. No new replies allowed.