C++ 如何使负数不显示? #包括 #包括 #包括 使用名称空间std; int main() { 浮球V1、V0、t; cout>t; 您可以使用cmath的abs #include <iostream> #include <iomanip&g

C++ 如何使负数不显示? #包括 #包括 #包括 使用名称空间std; int main() { 浮球V1、V0、t; cout>t; 您可以使用cmath的abs #include <iostream> #include <iomanip&g,c++,C++,如何使负数不显示? #包括 #包括 #包括 使用名称空间std; int main() { 浮球V1、V0、t; cout>t; 您可以使用cmath的abs #include <iostream> #include <iomanip> #include <string> using namespace std; int main() { float V1, V0, t; cout << fixed << show

如何使负数不显示?
#包括
#包括
#包括
使用名称空间std;
int main()
{
浮球V1、V0、t;
cout>t;

您可以使用cmath的abs

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
    float V1, V0, t;

    cout << fixed << showpoint << setprecision(2);

    cout << "Please enter starting V0, V1, and t in terms of seconds" << endl;
    cin >> V1 >> V0 >> t;
    cout << (V1 - V0) / t << endl;
    cin.get();
    cin.get();

    return 0;
}
#包括
...

您是否未能检查输入操作的结果。您在
V0
之前读取
V1
,但您要求用户在
V1
之前输入
V0
#include <cmath>
...
cout << abs((V1 - V0) / t) << endl;