Search code examples
c++trigonometrylogarithm

KSP DELTA V FINDER: Why does C++ assume that log( ) is a function?


I'm attempting to create a program to figure out Delta-V for my Kerbal Space Program game, and C++ (being run in the Eclipse IDE) does not allow for use of log() without assuming I'm trying to call a function. Thank you so much for help! It's really nice of you.`

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    cout << "Hello. Welcome to the Kerbal Space Program Delta V Calculator. \n";
    cout << " \n";
    cout << "Note that each stage must use the same engine for this calculator.";
    cout << "\n";
    cout << "\nHow many stages make up your rocket? :";
    int stageNumber;
    cin >> stageNumber;
    //cout << "Your rocket has " << stageNumber << " stages.\n";
    cout << "\n\nStart from the bottom stage, please. ";
    //ACTUAL DELTA V CALCULATIONS
    for(int currentStage = 1; currentStage <= stageNumber; currentStage = currentStage + 1){
        cout << "What is the total mass of this stage? :";
        int totalMass;
        cin >> totalMass;
        cout << "What is the fuel mass of this stage? :";
        int fuelMass;
        cin >> fuelMass;
        cout << "\n";
        int dryMass;
        dryMass = totalMass - fuelMass;
        cout << "Your dry mass is" << dryMass << "\n";
        cout << "\n";
        cout << "Give the specific impulse of this stage's engine. \n";
        int iSP;
        cin >> iSP;
        cout << "Here is the Delta V of your rocket.\n";
        int deltaMass;
        deltaMass = totalMass/dryMass;
        int deltaV;
        deltaV = iSP * log(deltaMass);
        cout << deltaMass

        exit(0);
    }

}

`


Solution

  • log() is a function in the C standard library that takes the natural logarithm of a number. The name is effectively reserved — pick something else.