我如何获得加速度值?

问题描述 投票:0回答:1

我正在创建一个计算平均加速度的程序。它工作得很好,但是我似乎无法获得加速度的值。有人可以教我为什么会这样以及如何解决这个问题吗?寻求帮助的tq

#include <iostream>
using namespace std;

//--------------------------------------------------------------------------//
void Getdata(double &Vstart, double &Vend, double &time);
void calculate(double &Vstart, double &Vend, double &time, double &accel);
void Displayoutput(double &out);

//--------------------------------------------------------------------------//
int main() {
  double Vstart = 0.0;
  double Vend = 0.0;
  double time = 0.0;
  double accel,out = 0;

  cout << "please enter your velocity(Vo=m/s)\n,velocity(Vt=m/s)\nand time(s=second)\n\n";
  Getdata(Vstart, Vend, time);
  calculate(Vstart, Vend, time, accel);
  Displayoutput(out);
  return 0;
}

//--------------------------------------------------------------------------//
void Getdata(double &Vstart, double &Vend, double &time) {
  cin >> Vstart;
  cin >> Vend;
  cin >> time;
  cout << "your Vo=" << Vstart << " ,Vt=" << Vend << " and T=" << time << "\n\n";
}

//--------------------------------------------------------------------------//
void calculate(double &Vstart, double &Vend, double &time, double &accel) {
  accel = (Vstart - Vend) / time;
}

//--------------------------------------------------------------------------//
void Displayoutput(double &out) {

  cout << "the acceleration =" << out;
}

//--------------------------------------------------------------------------//
c++ pass-by-reference
1个回答
0
投票

更改

Displayoutput(out);

to

Displayoutput(accel);
© www.soinside.com 2019 - 2024. All rights reserved.