2014-02-12 4 views
0

나는 추적 할 것입니다. C++에서 구형 객체가 클래스에 대해 bouyant인지 아닌지 계산하는 프로그램을 만들었습니다. 그러나 내가 (필자가 생각한) 필자가 Visual Studio 2013에서 프로그램을 만들었을 때 (Pearon의 끔찍한 myProgrammingLab) Pearon 's에 비해 출력이 잘못되었습니다. (IE : 광산은 그들이 싱크 말하지만, 계산 자체를 표시하지 않습니다, 그것은 수레 말한다.) 여기 C++에서 보양을 계산할 때 알 수없는 문제가 발생했습니다.

내 코드입니다 :이되지 않는 이유

// Bouyancy formula: 
// Fb = V * y 
// Where: 
// Fb is the bouyant force 
// V is the volume of the submerged object 
// y is the specific weight of the fluid 
// If Fb is greater than or equal to the weight of the object, then it will float, otherwise it will sink. 

// Sphere volume formula: 
// (4/3)pi(radius cubed) 

#include "stdafx.h" 
#include <iostream> 
#define _USE_MATH_DEFINES // Used with math.h to provide access to M_PI (used in calculation of volume) 
#include <math.h> // M_PI is the value of pie (3.14..) 

using namespace std; 

int main() 
{ 
    float sphere_radius, sphere_weight; // Stores the value of the Sphere's radius and weight in feet and pounds respectively. 
    double water_weight = 62.4; // Value set to 62.4lb /cubic feet, this value is the "y" value in the above formula. 
    double bouyant_force, volume; // Defines Fb and V in the Bouyancy formula listed above. 

    cout << "Enter the radius of the sphere, in feet: "; 
    cin >> sphere_radius; 
    cout << "\nEnter the weight of the sphere, in pounds: "; 
    cin >> sphere_weight; 
    cout << endl; 

    volume = ((4.0/3.0) * M_PI * (pow(sphere_radius, 3))); // Calculates the volume of the sphere 
    bouyant_force = (volume * water_weight); 
    if (bouyant_force >= sphere_weight) 
    { 
     cout << "The sphere will float." << endl; 
    } 
    else if (bouyant_force < sphere_weight) 
    { 
     cout << "The sphere will sink." << endl; 
    } 
    else { cout << "Something went terribly, terribly, wrong.. Oh dear.."; } 

    char x; 
    cin >> x; //Waits for user to press a key before closing the program. 
    return 0; 
} 

사람이 나를 이해하는 데 도움 주실 래요 또는 왜 그것이 올바르게 등록되지 않은 이유는 무엇입니까? 미리 감사드립니다!

답변

1

코드로 판단하면 부력과 맞먹는 무게를 직접 비교하는 것 같습니다. 사용하는 단위계에서 수용하는 질량 (파운드는 질량의 단위)을 g로 곱해야합니다. 다른 쪽에서는 그것이 가라 앉는 동안 그것을 계산하는 동안 당신은 그것을 계산하는 것처럼 보입니다.

+0

이 사이트는 중력을 계산에 포함시키지 않은 특정 공식을 우리에게 제공했습니다. 그러나, 나는 그것을 시도, 감사합니다 편집 : 같은 문제 – ArnoldM904

+0

@ Scarecrow 물리학에서 무게는 질량과 동일하지 않습니다. 예 : [Wikipedia] (https://en.wikipedia.org/wiki/Weight). (간체 : 무게는 중력에 의해 질량이 조정됩니다.) – molbdnilo

관련 문제