0

:) 我在使用 c++ 时遇到问题(我是初学者,哈哈)我在发布 .exe 方面需要帮助我在 Code::Blocks 中运行我的程序,一切正常......但是当我运行独立的 .exe 时不起作用。:( 我的代码包含“cmath”,所以我认为这可能会导致问题?我的程序是这样工作的:它询问用户他们的汽车重量和 1/4 英里的陷阱速度。它通过一个等式运行这些数字://公式= HP = [(MPH/234)^3] * Weight 用户可以输入重量,但是当输入陷阱速度时,程序就会关闭:\(通过程序我指的是独立版本.exe)。一切正常C::B. 如果你们中的任何一个专业人士可以提供帮助,那就太好了。谢谢 -Evan... 代码:

#include <iostream>
#include <cmath>

using namespace std;


//Formula = HP = [(MPH/234)^3] * Weight

int main()
{
    cout << "Source for formula:" << endl <<"http://beatersbanter.blogspot.com/2011/08/how-to-calculate-horsepower-from.html" << endl;
    cout << "Let's calculate your horsepower!" << endl << "I just need some car stats first..." << endl;

    float whp = 0;
    float weight = 0;
    float mph = 0;
    float mphdivided = 0;

    cout << "Enter weight (pounds):" << endl;
    cin >> weight;

    cout << "Enter quarter mile trap speed (mph):" << endl;
    cin >> mph;

    mphdivided = mph / 234;
    whp = pow(mphdivided, 3) * weight;

    cout << "Great!" << endl << "Your wheel horsepower rating is: " << whp << endl;
    cout << "Thank you for your time!" << endl;

    return 0;
}
4

1 回答 1

3

它只是打开并立即关闭,对吗?添加getchar()cin >> variablevariable您选择的变量在哪里:

char c;
cin >> c; //add this or getchar();
于 2013-11-11T00:30:58.233 回答