c++ - My program will run but it prints out all 100's for values that should be all different -


my program run when reaches point prints out vector values come out 100, far programming skills go (which pretty low) see no reason should creating values 100. think may have input_seconds im not sure. suggestions on whats wrong?

#include<iostream> #include<cmath> #include<vector> using namespace std;  double altitude(){     double alti;     cout << "please input altitude in meters:";     cin >> alti;     return alti; }  double roc() {     double climbr;     cout << "please input climb rate in m/s:";     cin >> climbr;     return climbr; }  double speed(){     double v;     cout << "please input current speed on ground in m/s" << endl;     cin >> v;     return v; }  //  gives time take reach desired altitude double time(double a, double r){     double t;     t = / r;     return t; }  //distance travelled horizontally in given time double distancetravelled(double veloc, double time){     double d;     d = veloc*time;     return d; }  //this convert time days, hours, minutes, , seconds. vector<double> converted_time(double input_seconds){     double days;     double hours;     double minutes;     double seconds;     days = input_seconds / 60 / 60 / 24;     hours = (input_seconds / 60 / 60) / 24;     minutes = (input_seconds / 60) / 60;     seconds = (input_seconds) / 60;     //puts values vector     vector<double>times;     times[0] = days;     times[1] = hours;     times[2] = minutes;     times[3] = seconds;      return times; }  void print_vector(vector<double>converted_time){     cout << "the time take plane reach desired altitude ";     cout << converted_time[0] << " days, " << endl;     cout << converted_time[1] << " hours, ";     cout << converted_time[2] << " minutes , ";     cout << converted_time[3] << " seconds" << endl; }  void print_result (double v, double d){     cout << "the distance on ground travel ";     cout << d << " meters"<<endl; }  int main(){     double a;     double r;     double t;     double v;     double d;     r = roc();     = altitude();     t = time(a, r);     vector<double>converted_time(4);      double days = converted_time[0];     double hours = converted_time[1];      double minutes = converted_time[2];     double seconds = converted_time[3];      v = speed();     d = distancetravelled(t,v);      print_result(v, d);     print_vector(converted_time);     return 0; } 

need change

hours = (input_seconds / 60 / 60) / 24; minutes = (input_seconds / 60) / 60; seconds = (input_seconds) / 60; 

to

hours = ((int)input_seconds / 60) / 60; input_seconds -= (int)hours * 60 *60; minutes = ((int)input_seconds / 60); input_seconds -= (int)minutes * 60; seconds = (int)input_seconds; 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -