Problem beim Rechnen (manuell berechnetes Ergebnis != Programmausgabe)



  • Hallo,

    Ich habe mit folgender Herausforderung zu kämpfen: Ich komme bei einer relativ einfachen Berechnung einfach nicht auf das richtige Ergebnis im Programm. Ich habe mich durchgeackert durch viele Beiträge und unzählige für mich vorstellbare Feherquellen und habe meiner Meinung nach alle notwendigen Deklarationen und Besonderheiten beim Arbeiten mit "double" variablen durchgeführt und beachtet. Es geht um folgendes Problem. Ich möchte das Takeoffweight eines Flugzeuges berechnen lassen, bestehend aus dem vordefinierten Leergewicht, dem Gewicht aller Passagiere (Anzahl der Passagiere wird durch cin definiert) inkl. Gepäck (= toweightbasic) sowie dem zuvor auf ähnliche Weise erfolgreich berechneten Treibstoff in Pfund. Ich hatte einige Zeilen zuvor ein ähnliches Problem beim Ermitteln der empfohlenen Sinkrate, da ließ es sich aber durch das richtige Definieren mit xx.00 beispielsweise und das Rechnen ohne Zahlenwerte, also nur mit Variablen, lösen. Nur hier geht es einfach nicht. Ich habe meinen Taschenrechner gezückt und genauso wies im Quellcode steht 1:1 eingegeben und komme auf 146500 lbs während das Programm ausgibt: 1.03069e+265 bzw. bei einem anderen Testlauf weniger als das, was vorher für das Treibstoffgewicht rauskommt. Treibstoffgewicht bei jedem Durchlauf: 44630.6. Für toweightbasic = passengers*pasandluggageStdWeight kommt der korrekte Wert, nämlich 22880 lbs raus bei 104 Passagieren und 220 lbs als Standardgewicht pro Passagier (inkl. Gepäck). Anbei ein kompilierbarer Teil meines Codes, wäre für baldige Hilfe sehr dankbar. Ich übersehe ganz sicher was.
    Liebe Grüße,

    Martin

    #include <iostream>
    #include <cmath>
    #include <windows.h>
    #include <cstring>
    
    using namespace std;
    
    int main()
    
    {
    
    // Definition of aircraft to use:
    
    string aircraft;
    
    cout << "Please tell me which aircraft you wanna use (ICAO): "; getline(cin, aircraft);
    
    // Aircraft ICAO Codes für eure Tests: Boeing 737 = B738; Boeing 747 = B744, Learjet 45 = LJ45;
    
    // Cruise fuel (hier manuell definiert, da es sich ja nur um einen Ausschnitt handelt)
    double cruisefuelgtog = 44630.6;
    // TOW and TOS Variables
                    double pasandluggageStdWeight = 220.0; // lbs
                    cout << pasandluggageStdWeight; // Testausgabe
                    double passengers; // user input
                    double emptyweightb738 =  90170.0; // lbs
                    cout << emptyweightb738; // Testausgabe
                    double emptyweightb744 = 404845.0; // lbs
                    cout << emptyweightb744; // Testausgabe
                    double emptyweightlj45 =  13550.0; // lbs
                    cout << emptyweightlj45; // Testausgabe
    
                    double reftakeoffweightb738 = 140507.0; // lbs
                    double reftakeoffspeedb738 = 163.0; // knots
                    double reftakeoffweightb744 = 846365.0; // lbs
                    double reftakeoffspeedb744 = 205.0; // knots
                    double reftakeoffweightlj45 = 20500.0; // lbs
                    double reftakeoffspeedlj45 = 175.0; // knots
    
                    double maxtakeoffweightb738 = 172500.0; // lbs
                    double maxtakeoffweightb744 = 910000.0; // lbs
                    double maxtakeoffweightlj45 =  20500.0; // lbs
    
                    double takeoffweight;
                    double takeoffspeed;
                    // TOW and TOS Calculation
    
                    cout << "Please enter the no. of passengers for this trip (no+.0): "; cin >> passengers;
                    cout << passengers; // Testausgabe
                    double toweightbasic = passengers*pasandluggageStdWeight; cout << toweightbasic;
                    cout << "Calculating take off weight and speed";
                    for(int i=1; i<=5;++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    if(aircraft == "B738")
                    {
                        takeoffweight = emptyweightb738+toweightbasic+cruisefuelgtog;
                        takeoffspeed = (takeoffweight/reftakeoffweightb738)*reftakeoffspeedb738;
                    }
                    if(aircraft == "B744")
                    {
                        takeoffweight = emptyweightb744+toweightbasic+cruisefuelgtog;
                        takeoffspeed = (takeoffweight/reftakeoffweightb744)*reftakeoffspeedb744;
                    }
                    if(aircraft == "LJ45")
                    {
                        takeoffweight = emptyweightlj45+toweightbasic+cruisefuelgtog;
                        takeoffspeed = (takeoffweight/reftakeoffweightlj45)*reftakeoffweightlj45;
                    }
                    cout << "Takeoff weight: " << takeoffweight << " lbs\n" << "Takeoff speed: " << takeoffspeed << " knots. Press 'Enter'!"; cin.get();
                    if(aircraft == "B738")
                    {
                        cout << "Maximum Takeoff Weight: " << maxtakeoffweightb738 << endl; Sleep(1000);
                    }
                    if(aircraft == "B744")
                    {
                        cout << "Maximum Takeoff Weight: " << maxtakeoffweightb744 << endl; Sleep(1000);
                    }
                    if(aircraft == "LJ45")
                    {
                        cout << "Maximum Takeoff Weight: " << maxtakeoffweightlj45 << endl; Sleep(1000);
                    }
    
    return 0;
    
    }```cpp
    
    


  • Hi,

    ich hab gerade den Code selbst getestet und komme genau auf die richtigen Ergebnisse! Ich habe aber auch von den iputs alles genauso gemacht.

    Da dieser Testteil allerdings nur aus meinem Hauptcode rauskopiert und lauffähig gemacht wurde, bin ich aber immer noch nicht weiter. Ich kopiere hier deshalb mal sicherheitshalber meinen gesamten Code ins Forum. Ich weiß, sollte ich nicht aber vl ist irgendwo anders der Fehler begraben.

    // Aviation Program 1.0
    // Name of Program: Ave
    // Copyright by Martin Pardatscher
    // This program is intended to make life easier for pilots who are preparing their flights.
    // It is also meant to be used as a quick theoretical training application
    
    #include <iostream>
    #include <ctime>
    #include <windows.h>
    #include <MMSystem.h>
    #include <cstring>
    #include <fstream>
    #include <cmath>
    
    using namespace std;
    
    int points[7]; // Zählung von 0-6 aber 0-6 sind ja genauso 7 Felder wie 1-7!
    // Functions for calculations, explanations, etc. (see Memo for further info about the meaningful usage of functions)
    
    // Global variables:
    
    // main function
    int main()
    {
        // Variables for the correct execution of the menu
        char mchoice;
        long int authnumber;
        string pwd;
        long int authnumberC; // VATSIM ID
        string pwdC; // VATSIM PWD
        ifstream infile;
        ofstream outfile;
        // Starting process
        clock_t start, end;
        start = clock();
    
        cout << "Starting up...\n"; Sleep(3000);
        cout << "Loading necessary items...\n"; Sleep(1000);
        // Starting Music
        // PlaySound(TEXT("BoardMusic3.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
        // PlaySound(TEXT("Vivaldi.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
        // PlaySound(TEXT("FlylikeanEagleStMi.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
        PlaySound(TEXT("FSX02.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
        // Starting vpilot and firefox for testing
        // ShellExecute(NULL, "open", "C:\\Users\\Martin\\AppData\\Local\\vPilot\\vPilot.exe",NULL,NULL,SW_SHOW); // funkt
        ShellExecute(NULL, "open", "firefox.exe",NULL,NULL,SW_SHOW); // funkt
        // Display of elapsed time
        end = clock();
        cout << start << endl;
        cout << end << ':' << CLOCKS_PER_SEC << endl;
    
    	// Saving current time from struct tm
    	time_t Zeitstempel;
        tm *nun;
        Zeitstempel = time(0); // Variable wird Wert, der durch Funktion time(0) zurückgegeben wird, zugewiesen
        nun = localtime(&Zeitstempel); // Möglichkeit zum Speichern zweier Werte in einer Variable
        // Showing current time
        cout << nun->tm_mday << '.' << nun->tm_mon+1 << '.'
            << nun->tm_year+1900 << " - " << nun->tm_hour
            << ':' << nun->tm_min << endl;
            Sleep(1000);
            // Influenced greeting
        if(nun->tm_hour < 6 && nun->tm_hour < 11)
        {
            cout << "Good morning captain!\n";
        }
        else if(nun->tm_hour > 12 && nun->tm_hour < 18)
        {
            cout << "Good afternoon captain!\n";
        }
        else
        {
            cout << "Good evening captain!\n";
        }
        //  Menu
        do // Schleife funktioniert perfekt und man wird wieder zum Ausgangspunkt zurück geleitet. Sicherheitsaspekt: Vor jedem AUfrufen des Menus ern. Login.
        // Vermeidung: do { vor // Menu Intro
        {
        // Login process
            cout << "Please login to continue! ID: "; cin >> authnumber; cin.ignore();
            cout << "Password: "; getline(cin, pwd);
            cout << "Thank you! Checking your information...\n"; Sleep(2000);
            infile.open("VATSIM.txt");
            infile >> authnumberC;
            infile.close();
            while(authnumber != authnumberC)
            {
                cout << "User not found! Please try again! Are you registered? If not, copy and paste this link to your browser: https://www.vatsim.net/join" << endl <<
                "ID: "; cin >> authnumber; cin.ignore();
                cout << "Thank you! Checking...\n"; Sleep(2000);
            }
            cout << "User correct!\n";
            infile.open("VATSIM.txt");
            for(int i=1; i<=2; ++i)
            /* Mit jedem Ausführen des LeseBefehls innerhalb der Schleife wird die Zählervariable i um 1 erhöht, bis sie den Wert 2 erreicht.
            Zu diesem Zeitpunkt ist der Cursor am Ende der Zeile 2 angelangt, da die Datei noch geöffnet ist! */
            {
                getline(infile, pwdC);
            }
            infile.close();
            cout << "Checking password...\n"; Sleep(1000);
            /* alle Daten werden richtig eingelesen */
            // Workaround in case of wrong password:
            cout << "Please provide your password again: "; getline(cin, pwd);
    
            while(pwd != pwdC); /* ich gebe das richtige Passwort ein und er geht in die Schleife und ich muss es nochmals eingeben!
            Wenn ich es beim ersten Mal falsch eingebe, dann hängt er. Wenn ich es innerhalb der Schleife falsch eingebe, dann geht er weiter, wie wenn Bedingung
            nicht mehr erfüllt wäre! */
            {
                cout << "Password is not correct or there's a temporary error! It will be automatically sent and we apologize for any inconvenience! " <<
                "Please try again! Password: "; getline(cin, pwd);
                cout << "Thank you checking...\n"; Sleep(2000);
            }
            // Menu intro
            cout << "Welcome! My Name is Ave, your personal flight worker today! What can I do for you?" << endl <<
            "You might choose from the following options: (Q)uick testing, (P)lanning, (A)TC Training, (E)xit! Your Choice: ";
            cin >> mchoice; cin.ignore();
            string pilotname;
            switch(mchoice)
            {
                case('Q'):
                {
                    cout << "Your test will start shortly...\n"; Sleep(3000);
                    // Variables for quiz:
                    string answer;
                    // Punkte array ist global!
                    // Quiz
                    cout << "Please tell me your name: "; getline(cin, pilotname);
                    cout << "Welcome! Within the next minutes, you will be confronted with a wide choice of basic as well as common questions and" <<
                    " problems pilot's may have! The test is multiple choice and sometimes there can be more than one answer correct! There is no time limit!" <<
                    " Think carefully and have fun! :-)" << endl << "Press Enter 2x to continue!";  cin.get(); cin.ignore();
                    cout << "Quiz is loading...\n\n"; Sleep(2000);
    
                    cout << "Question 1: What must every pilot do before each (!) flight?" << endl << "A: Outside check" << endl << "B: Flaps to full extent" << endl
                    << "C: Calculate takeoff weight and speed" << endl << "D: Calculate flaps' setting" << endl << "Your answer: "; getline(cin, answer);
                    string answerQ1C = "A C D";
                    cout << "Your Answer was: " << answer << "...\n"; Sleep(1000);
    
                    if(answer != answerQ1C)
                    {
                        cout << "Wrong! The pilot has always to do an outside check before each flight, to make sure the aircraft has taken no harm by" <<
                        " the previous flight." << endl <<
                        "The flaps' setting depends on weather conditions, takeoff weight as well as on the surroundings of the departure airport.\n" <<
                        "Calculating takeoff weight and speed or at least a quick check (only by the same crew) before the next flight is mandatory to know" <<
                        " the correct takeoff settings and if they are allowed to takeoff (reference!). In addition they need to make sure that every single" <<
                        " passenger whose luggage is on board is also there!\n";
                        points[0] = 0;
                        cout << "Your achieved points: " << points[0] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    else
                    {
                        cout << "Correct! In addition they need to make sure that every single passenger whose luggage is on board is also there!\n";
                        points[0] = 3;
                        cout << "Your achieved points: " << points[0] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    cout << "Proceeding to next question...\n\n"; Sleep(3000);
    
                    cout << "Question 2: Which of the following flight rules exist?\n" << "A: ILS\n" << "B: ISR\n" << "C: VFR\n" << "D: all three of them\n" <<
                    "Your Answer: "; getline(cin, answer); string answerQ2C = "A C";
                    cout << "Your Answer was: " << answer << "...\n"; Sleep(1000);
    
                    if(answer != answerQ2C)
                    {
                        cout << "Wrong! ISR does not exist and therefore answer D must be incorrect!\n";
                        points[1] = 0;
                        cout << "Your achieved points: " << points[1] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    else
                    {
                        cout << "Correct! ILS is commonly used for landing at large Airports and when weather conditions do not allow landing on VFR\n" <<
                        "Side fact: A pilot can almost always decide by himself which approach system he wants to use, but there are different rules\n";
                        points[1] = 2;
                        cout << "Your achieved points: " << points[1] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    cout << "Proceeding to next question...\n\n"; Sleep(3000);
    
                    cout << "Question 3: Which navigation path(s) is (are) usually used for arrival at a controlled airport?\n" <<
                    "A: STAR\n" << "B: SSID\n" << "C: SID\n" << "D: VOR\n" << "Your Answer: "; getline(cin, answer); string answerQ3C = "A C";
                    cout << "Your Answer was: " << answer << "...\n"; Sleep(1000);
    
                    if(answer != answerQ3C)
                    {
                        cout << "Wrong! SSID is the name for wireless networks! Commonly used Navigation paths on controlled (!) airports are:\n" <<
                        "STAR\n" << "SID\n" << "VOR can also be used for airports without a ATC and without an ILS localizer!\n";
                        points[2] = 0;
                        cout << "Your achieved points: " << points[2] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    else
                    {
                        cout << "Correct!\n";
                        points[2] = 2;
                        cout << "Your achieved points: " << points[2] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    cout << "Proceeding to next question...\n\n"; Sleep(3000);
    
                    cout << "Question 4: Which claims about the rudder of an aircraft are not correct?\n" << "A: it controls the steering of the aircraft\n" <<
                    "B: it helps braking the aircraft down on ground\n" << "C: it can be used for runway alignment\n" <<
                    "D: it is used by the autopilot for stabilizing\n" << "Your answer: "; getline(cin, answer); string answerQ4C = "B D";
                    cout << "Your Answer was: " << answer << "...\n"; Sleep(1000);
    
                    if(answer != answerQ4C)
                    {
                        cout << "Wrong! If winds are heavy at final approach, pilots often use the rudder to keep the plane aligned to the runway!\n" <<
                        "Why? Because the rudder does control the aircraft's steering!" << "It doesn't have any effect on the ground. It is moved because" <<
                        " the pedals for the rudder function as brake pedals on the ground like for a car!\n" << "The autopilot can't control the rudder" <<
                        " by default\n";
                        points[3] = 0;
                        cout << "Your achieved points: " << points[3] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    else
                    {
                        cout << "Correct!\n";
                        points[3] = 2;
                        cout << "Your achieved points: " << points[3] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    cout << "Proceeding to next question...\n\n"; Sleep(3000);
    
                    cout << "Question 5: In case of a (an oncoming) stall, what should you immediately do?\n"
                    << "A: Switch off all automatic controls (including ATHR) -> Thrust to 100 -> carefully push the nose down -> balance the nose, control" <<
                    "turn and thrust smoothly, keeping it always leveled until the aircraft's nose is stabilized again!\n" <<
                    "B: I don't know! I would be helpless and panic\n" << "C: Get my hands off the controls and let technology do the rest!\n"
                    << "Your Answer: "; getline(cin, answer);
                    string answerQ5C = "A";
                    cout << "Your Answer was: " << answer << "...\n"; Sleep(1000);
    
                    if(answer != answerQ5C)
                    {
                        cout << "Wrong! The only way to avoid or get out of a stall is the procedure mentioned by A!\n"
                        << "Reason: When the aircraft stalls, it means that the air stream is cut and therefore the nose will drop hard and the danger of an " <<
                        " uncontrollable spin will rise rapidly!\n";
                        points[4] = 0;
                        cout << "Your achieved points: " << points[4] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    else
                    {
                        cout << "Correct!\n";
                        points[4] = 1;
                        cout << "Your achieved points: " << points[4] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    cout << "Proceeding to next question...\n\n"; Sleep(3000);
    
                    cout << "Question 6: If you are experiencing a problem, what is the correct call to ATC?\n" <<
                    "A: Mayday!\n" << "B: Pan, Pan, Pan\n" << "C: it depends on its nature and (or) urgency\n" <<
                    "Your Answer: "; getline(cin, answer);
                    string answerQ6C = "C";
                    cout << "Your Answer was: " << answer << "...\n"; Sleep(1000);
    
                    if(answer != answerQ6C)
                    {
                        cout << "Wrong! It always depends on the nature and (or) the urgency of the problem!\n";
                        points[5] = 0;
                        cout << "Your achieved points: " << points[5] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    else
                    {
                        cout << "Correct!\n";
                        points[5] = 1;
                        cout << "Your achieved points: " << points[5] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    cout << "Proceeding to next question...\n\n"; Sleep(3000);
    
                    cout << "Question 7: You and your flight crew just arrived in the cockpit! In which order should you do the ATC procedures?\n" <<
                    "A: Clearance delivery\n" << "B: Request pushback and startup clearance\n" << "C: Request Info from ATIS\n" << "D: Inform the ground" <<
                    " controller that you're ready to taxi!\n" << "Your Answer: "; getline(cin, answer);
                    string answerQ7C = "C A B D";
                    cout << "Your Answer was " << answer << "...\n"; Sleep(1000);
    
                    if(answer != answerQ7C)
                    {
                        cout << "Wrong! You should always follow the following order: C A B D\n";
                        points[6] = 0;
                        cout << "Your achieved points: " << points[6] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
                    else
                    {
                        cout << "Correct!\n";
                        points[6] = 4;
                        cout << "Your achieved points: " << points[6] << endl << "Press 'Enter' 2x to continue";
                        cin.get(); cin.ignore();
                    }
    
                    cout << "Congratulations! You have reached the end of the quiz! Please wait while your points are calculated...\n\n";
                    Sleep(1000);
                    int topoints = points[0]+points[1]+points[2]+points[3]+points[4]+points[5]+points[6]; // eigene Funktion nur OHNE ARRAYS;
                    // += wenn zwei bestimmte dynamische Werte!
                    int maxpoints = 15;
                    cout << "You have reached " << topoints << " of " << maxpoints << " points!\n";
                    if(topoints == 0 || topoints > 0 && topoints <= 3) // 5er
                    {
                        cout << "Did you really do your best? Try again! :-)\n";
                    }
                    else if(topoints > 3 && topoints <= 6) // 4er
                    {
                       cout << "You proved, that you have at least some knowledge, but you can certainly do much better! :-)\n";
                    }
                    else if(topoints > 6 && topoints <= 9) // 3er
                    {
                        cout << "Your level of knowledge is quite sufficient, just read through some info again and you will be perfectly prepared! :-)\n";
                    }
                    else if(topoints > 9 && topoints <= 12) // 2er
                    {
                        cout << "Quite good! Just a little more! :-)\n";
                    }
                    else
                    {
                        cout << "Great job captain!\n";
                    }
    
                    cout << "Returning to main menu...\n"; Sleep(3000);
    
                } break;
    
                case('P'):
                {
                    cout << "Loading Planning tool... One Moment please...\n\n"; Sleep(3000);
                    cout << "Please tell me your name: "; getline(cin, pilotname);
                    // Departure point
                    string DepAirport; // substring
                    string ICAOdep;
                    cout << "To start, please provide the name of your departure airport: "; getline(cin, DepAirport);
                    cout << "Loading list where to find ICAO Codes! Please search and take a note of the airport you need! Thanks!\n";
                    cout << "To search for the name use CTRL+F and type the name!\n";
                    for(int i=1; i<=2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
    
                    ShellExecute(NULL, "open", "ICAO.txt", NULL, NULL, SW_SHOW);
    
                    /*
                    // Find first INDEX of substring DepAirport (only works for 1line documents)
                    size_t searchresult=ICAOlist.find(DepAirport); // size t ist index variable!
                    if(searchresult != string::npos)
                    {
                        cout << "ICAO Code: " << searchresult << endl; // Die SPALTE wird als int ausgegeben. Das heißt, wo ist es zu finden?
                    }
                    */
    
                    // Searching option fourd? Comment out everything no more needed and type here
    
                    /* for(int i=1; i<=11234 ;++i)
                    {
                        getline(infile, ICAOlist);
                        cout << ICAOlist << endl; Sleep(40);
                    } */
                    cout << "ICAO of Departure airport: "; getline(cin, ICAOdep);
                    cout << "Saving";
                    for(int i=1; i<=2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << "Flight Plan for: " << pilotname << endl << endl;
                    outfile << "Departure Airport (ICAO): " << ICAOdep << endl;
                    outfile.close();
                    cout << "Data saved successfully!\n";
                    // GATE
                    string gate;
                    cout << "Please define the gate manually! Your selection: "; getline(cin, gate);
                    cout << "Saving...\n"; Sleep(500);
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << "Gate: " << gate << endl;
                    outfile.close();
                    // Local Time
                    string loctime;
                    cout << "Retrieving local time";
                    for(int i=1; i<=2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    cout << "Please copy and paste the following link in your favourite browser: https://www.timeanddate.com/worldclock///!\n" <<
                    "Please provide the local time of your departure city (if you cannot find it just google!): "; getline(cin, loctime);
                    cout << "Saving data";
                     for(int i=1; i<=2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << "Local Time: " << loctime << endl;
                    outfile.close();
                    cout << "Data saved successfully!\n"; Sleep(1000);
                    // Destination airport
                    string ICAOdest;
                    cout << "Where do you wanna go?\n" << "Destination (ICAO): ";
                    Sleep(1500);
                    ShellExecute(NULL, "open", "ICAO.txt", NULL, NULL, SW_SHOW);
                    getline(cin,ICAOdest);
                    cout << "Saving";
                    for(int i=1; i<= 2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << "Destination airport (ICAO): " << ICAOdest << endl;
                    outfile.close();
                    cout << "Data saved successfully!\n";
                    string DestAirport;
                    cout << "Please provide the name of your destination: "; getline(cin, DestAirport);
                    // Aircraft
                    string aircraftlist;
                    string aircraft;
                    cout << "Please choose your aircraft for this flight from the list being opened!\n";
                    for(int i=1; i<= 2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    cout << "Aircraft (ICAO): "; Sleep(2000);
                    ShellExecute(NULL, "open", "Aircrafts.txt", NULL, NULL, SW_SHOW);
                    cin.ignore();
                    getline(cin, aircraft);
                    cout << "Saving";
                    for(int i=1; i<= 2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << "Aircraft: " << aircraft << endl;
                    outfile.close();
                    cout << "Data saved successfully!\n";
                    // Airline and Flightnumber
                    string airlineslist;
                    string airline;
                    string flightnumber;
                    string airlineICAO;
                    cout << "Please select your airline from the list being opened! Please take a note when you have found the one you're looking for!\n";
                    Sleep(1500);
                    ShellExecute(NULL, "open", "Airlines.txt", NULL, NULL, SW_SHOW);
                    cout << "Airline: "; getline(cin, airline);
                    cout << "Flightnumber (google flights): "; getline(cin, flightnumber);
                    cout << "ICAO Code of Airline (Link will be opened): "; Sleep(1500);
                    ShellExecute(NULL, "open", "http://www.flugzeuginfo.net/table_airlinecodes_airline_dt.php", NULL, NULL, SW_SHOW);
                    getline(cin, airlineICAO);
                    cout << "Saving.";
                    for(int i=1; i<= 2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << "Airline: " << airline << " " << flightnumber << "(" << airlineICAO << ")" << endl;
                    outfile.close();
                    cout << "Data saved successfully!\n";
                    // Distance
                    double DepLat;
                    double DepLon;
                    double DestLat;
                    double DestLon;
                    double distanceDepDest;
                    double distanceDepDestNM;
                    cout << "Please provide the geographical data of your departure airport (Link will be opened)! " <<
                    "(Decimal degrees Latitude): "; Sleep(1500);
                    ShellExecute(NULL, "open", "https://developers.google.com/maps/documentation/geocoding/intro#GeocodingRequests", NULL, NULL, SW_SHOW);
                    cin >> DepLat;
                    cout << "Longitude: "; cin >> DepLon;
                    cout << "Now the same for your destination! Latitude: "; Sleep(1500);
                    ShellExecute(NULL, "open", "https://developers.google.com/maps/documentation/geocoding/intro#GeocodingRequests", NULL, NULL, SW_SHOW);
                    cin >> DestLat;
                    cout << "Longitude: "; cin >> DestLon; cin.ignore();
    
                    cout << "Calculating distance";
                    for(int i=1; i<= 5; ++i)
                    {
                       cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    long double pi = 3.141592653589793238462643383279502884;
                    long double DepLatArc = ((2*pi)/360)*DepLat;
                    long double DepLonArc = ((2*pi)/360)*DepLon;
                    long double DestLatArc = ((2*pi)/360)*DestLat;
                    long double DestLonArc = ((2*pi)/360)*DestLon;
                    distanceDepDest=6378.388 * acos(sin(DepLatArc) * sin(DestLatArc) + cos(DepLatArc) * cos(DestLatArc) * cos(DestLonArc - DepLonArc));
                    cout << "The distance between " << DepAirport << " and " << DestAirport << " is " << distanceDepDest << " km!\n";
                    cout << "Converting to nautical miles";
                    for(int i=1; i<= 2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    distanceDepDestNM = distanceDepDest*0.539957;
                    cout << "Distance in nautical miles: " << distanceDepDestNM << " nm\n";
                    cout << "Saving";
                    for(int i=1; i<= 2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << "Distance: " << distanceDepDestNM << " nm" << endl;
                    outfile.close();
                    cout << "Data successfully saved\n";
                    // Flight Level (algorithm see fsx):
                    cout << "Calculating cruising altitude";
                    for(int i=1; i<= 2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    double cruisealt = 25*((distanceDepDestNM/20)-1);
                    double cruisealttrue = cruisealt*100;
                    if(cruisealttrue > 37000)
                    {
                        double cruisealttrueCor = (cruisealttrue -    cruisealttrue)+37000;
                        cruisealttrue = cruisealttrueCor;
                        cout << "Cruising altitude: " << cruisealttrue << " ft\n";
                        cout << "Saving";
                        for (int i=1;i <=2;++i)
                        {
                            cout << "."; Sleep(1000);
                        }
                        cout << ".\n\n";
                        outfile.open("Flightplan.txt", ios::out | ios::app);
                        outfile << "Cruising altitude: " << cruisealttrue << " ft" << endl;
                        outfile.close();
                        cout << "Data saved successfully\n\n";
                    }
                    else
                    {
                    cout << "Cruising Altitude: " << cruisealttrue << " ft\n";
                    cout << "Saving";
                    for(int i=1; i<= 2; ++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << "Cruising Altitude: " << cruisealttrue << " ft" << endl;
                    outfile.close();
                    cout << "Data saved successfully\n\n";
                    }
                    // Preparation for Calc of:
                    // Distance for descent
                    // Descent rate
                    cout << "Reading file containing airport and approach data and sorting for use (use in order listed)";
                    for (int i=1;i <=7;++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    // Airport Info
                    string frequencies; // All from Gate to Gate
                    // Template for file operation oppourtunities (do not use for further flight planning. It is too much and unnecessary work to create a file
                    // for each airport
                    FILE *in;
                    FILE *out;
                    char i = 255;
                    char path[i]; // Path to file depending on selected Airport
                    cout << "Please tell me where to search for the necessary frequencies of your defined departure airport (look up Frequencies.txt): ";
                    cin.get(path,254);
                    scanf("%254[^\n]", &path);
                    while(cin.get() != '\n') // Reading path
                    {
                        in = fopen(path, "r");
                    }
                    if(in == NULL) // Path does not exist or file not found
                    {
                        cout << " Path: " << path[i] << " does not exist or the requested file cannot be found! Please look up in the charts\n"; cin.get();
                    }
                    else
                    {
                        cout << "Valid path! Opening";
                        for(int i=1; i<=2;++i)
                        {
                            cout << "."; Sleep(1000);
                        }
                        cout << ".\n\n";
                    }
                    cout << "Writing";
                    for(int i=1; i<=2;++i)
                        {
                            cout << "."; Sleep(1000);
                        }
                        cout << ".\n\n";
    
                    infile.open(path);
                    for (int i=1;i<=5;++i)
                    {
                        cout << "Writing to flightplan... (if there is no data please look up what you need in the charts)"; Sleep(1000);
                        getline(infile, frequencies);
                        cout << frequencies << endl;
    
                        outfile.open("Flightplan.txt", ios::out | ios::app);
                        outfile << "Frequency: " << frequencies << " Mhz" << endl;
                        outfile.close();
                    }
                    infile.close();
                    // Calculation of cruise speed for descent rate within approach
                    cout << "Calculating approximate cruise speed (average)";
                    for(int i=1; i<=2;++i)
                    {
                            cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    double refcruisealt = 36000;
                    double refgroundspeed = 460; // knots
                    double cruisespeed = (refgroundspeed/refcruisealt)*cruisealttrue; // fehler drin! (professionell berechnen): Value of program: 275.27
                    // at 21543.7 ft
                    cout << "Your approximate cruise speed (GS in knots) is: " << cruisespeed << endl << "Please beware, that the value can vary depending on" <<
                    " aircraft type (can be seen in aircrafts' list), your true cruising altitude (-> ATC), Weight, Wind, etc! Press 'Enter'!\n\n"; cin.get();
                    cout << "Saving";
                    for(int i=1; i<=2;++i)
                    {
                            cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << "Approximate Cruise speed (GS in knots): " << cruisespeed << endl;
                    outfile.close();
                    // Approach <> Descent distance - EINGABE AUFFORDERUNG! (lt. Chart)
                    double altlocalizer;
                    cout << "Please look up the altitude of the localizer of your destination in your chart and tell me: "; cin >> altlocalizer;
                    cout << "Calculating, in which distance from the destination you have to begin to descend";
                    for(int i=1; i<=2;++i)
                    {
                            cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    double altitudedifference = (cruisealttrue-altlocalizer)*0.3048; // Conversion to meters (1 ft = 0.3048m)
                    double angleofdescent = 3*(pi/180); // degrees in rad <> Compiler arbeitet im RAD Modus!
                    double distdescent = ((altitudedifference/tan(angleofdescent))/1000)*0.54; // ((dist in meters)/1000 (for km))*0.54 = dist in nm
                    // Result of test calculation for altdiff = 33300 ft: app. 104.58 nm
                    cout << "You have to begin to descent " << distdescent << " nm from your destination! Press 'Enter'!\n"; cin.get();
                    cout << "Saving";
                    for(int i=1; i<=2;++i)
                    {
                            cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << " You have to begin to descent " << distdescent << " nm from your destination!" << endl;
                    outfile.close();
                    // Calculation of descent rate
                    cout << "Calculating rate of descent";
                    for(int i=1; i<=5;++i)
                    {
                            cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    double conversionfactorMtoFeet = 3.28084;
                    double decimalOneMinute = 0.0166666667;
                    long double requduration = distdescent/cruisespeed; cout << requduration << endl; cout << altitudedifference << endl;
                    long double descentrate = ((altitudedifference*conversionfactorMtoFeet)/requduration)*decimalOneMinute; // 1m = 1/60 h, Example: 33300 in 0.22735 h => Division and multiplied
                    // with 0.016666667 h = 2446,05 ft / min
                    cout << "The recommended rate of descent " << distdescent << " nm away from the Destination regarding the approximate GS is "
                    << descentrate << " ft/min\n";
                    cout << "Saving";
                    for(int i=1; i<=2;++i)
                    {
                            cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << "Recommended rate of descent: " << descentrate << " ft/min" << endl;
                    outfile.close();
                    // Fuel Calculation
                    cout << "Starting fuel calculation process";
                    string confirmexit = "yes";
                    for(int i=1; i<=2;++i)
                    {
                            cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    cout << "Please note that this process is currently only valid for Boeing Jets, Learjet 45 and IFR flights! Press 'Enter' to continue!";
                    cin.get();
                    double tripfuel;
                    long double fuelconsumptionB738 = 11.515625; // lbs / mi
                    long double fuelconsumptionB744 = 52.740125309832002203249793445332; // lbs / mi
                    long double fuelconsumptionLJ45 =  2.831698113207547169811320754717; // lbs / mi
                    double fuelparameterStd = 1.284503; // standardfactor
                    double addamountStd = 26814.12; // lbs
                    double addamountLJ45 = 3494.63; // lbs
                    double cruisefuelgtog;
                    string altairport;
                    cin.ignore();
                    cout << "Please confirm the aircraft you used previously by typing in the ICAO of the aircraft again: "; getline(cin, aircraft);
                    do
                    {
    
                        if(aircraft == "B738")
                        {
                            cout << "Calculating needed trip (!) fuel for Boeing 737-800\n";
                            for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            tripfuel = fuelconsumptionB738*distanceDepDestNM+addamountStd;
                            cout << "Suggested trip fuel: " << tripfuel << " lbs\n" << "Press Enter to continue"; cin.get();
                        }
                        else if(aircraft == "B744")
                        {
                            cout << "Calculating needed trip (!) fuel for Boeing 747-400\n";
                            for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            tripfuel = fuelconsumptionB744*distanceDepDestNM+addamountStd;
                            cout << "Suggested trip fuel: " << tripfuel << " lbs\n" << "Press Enter to continue"; cin.get();
                        }
                        else if (aircraft == "LJ45")
                        {
                            cout << "Calculating needed trip (!) fuel for Bombardier Learjet 45\n";
                            tripfuel = fuelconsumptionLJ45*distanceDepDestNM+addamountLJ45;
                            cout << "Suggested trip fuel: " << tripfuel << " lbs\n" << "Press Enter to continue"; cin.get();
                        }
                        else
                        {
                            cout << "No fuel calculation possible at the moment for the selected aircraft! Updates will follow! Press 'Enter' to continue"; cin.get();
                        }
                        // Calculation of true fuel from Gate to Gate
                        cout << "Multiplying with standard parameter";
                        for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                        double cruisefuelgtog = (tripfuel*fuelparameterStd);
                        // Division to tanks is and must be made by fueltruck!
                        double maxfuelb737 =  46062.50;
                        double maxfuelb744 = 382998.79;
                        double maxfuellj45 =   6003.20;
                        double fuelcorrection;
                        double correctedfuel;
    
                        cout << "The needed fuel amount for your cruise from Gate " << gate << " to the gate of your destination airport (will be instructed by "
                        << " ATC) is " << cruisefuelgtog << " lbs\n";
                        if(aircraft == "B738" && cruisefuelgtog > maxfuelb737)
                        {
                            cout << "Error! Maximum fuel for Boeing 737-800 is " << maxfuelb737 << "! Please enter the amount you wanna subtract!\n" <<
                            "Please beware that you might be forced to use an alternate airport!" << endl << "Correction amount: ";
                            cin >> fuelcorrection;
                            " Calculating";
                            for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            correctedfuel = cruisefuelgtog - fuelcorrection;
                            cout << "Corrected fuel amount: " << correctedfuel << "Press 'Enter to continue!"; cin.get();
                            cout << "Loading map for alternate airports";
                            for(int i=1; i<=2;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            ShellExecute(NULL, "open", "https://maps.google.com", NULL, NULL, SW_SHOW);
                            cin.ignore();
                            cout << "Please tell me the ICAO of your alternate airport: "; getline(cin, altairport);
                            cout << "Latitude: "; cin >> DestLat;
                            cout << "Longitude: "; cin >> DestLon;
                            cout << "Calculating distance";
                            for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            DestLatArc = ((2*pi)/360)*DestLat;
                            DestLonArc = ((2*pi)/360)*DestLon;
                            distanceDepDest=6378.388 * acos(sin(DepLatArc) * sin(DestLatArc) + cos(DepLatArc) * cos(DestLatArc) * cos(DestLonArc - DepLonArc));
                            cout << "The distance between " << DepAirport << " and your alternate Airport is " << DestAirport << " is " << distanceDepDest << " km!\n";
                            cout << "Converting to nautical miles";
                            for(int i=1; i<= 2; ++i)
                            {
                                cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            distanceDepDestNM = distanceDepDest*0.539957;
                            cout << "Distance in nautical miles: " << distanceDepDestNM << " nm\n";
                            cout << "Calculating fuel amount for Boeing 737-800";
                            for(int i=1; i<= 5; ++i)
                            {
                                cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            tripfuel = fuelconsumptionB738*distanceDepDestNM+addamountStd;
                            cout << "Trip fuel: " << tripfuel << " lbs\n";
                            cout << "Multiplying with standard parameter";
                            for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            cruisefuelgtog = (tripfuel*fuelparameterStd);
                            cout << "The needed fuel amount for your cruise from Gate " << gate << " to the gate of your alt. airport (will be instructed by "
                            << " ATC) is " << cruisefuelgtog << " lbs\n";
    
                        }
                        if(aircraft == "B744" && cruisefuelgtog > maxfuelb744)
                        {
                            cout << "Error! Maximum fuel for Boeing 747-400 is " << maxfuelb744 << "! Please enter the amount you wanna subtract!\n" <<
                            "Please beware that you might be forced to use an alternate airport!" << endl << "Correction amount: ";
                            cin >> fuelcorrection;
                            " Calculating";
                            for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            correctedfuel = cruisefuelgtog - fuelcorrection;
                            cout << "Corrected fuel amount: " << correctedfuel << "Press 'Enter to continue!"; cin.get();
                            cout << "Loading map for alternate airports";
                            for(int i=1; i<=2;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            ShellExecute(NULL, "open", "https://maps.google.com", NULL, NULL, SW_SHOW);
                            cin.ignore();
                            cout << "Please tell me the ICAO of your alternate airport: "; getline(cin, altairport);
                            cout << "Latitude: "; cin >> DestLat;
                            cout << "Longitude: "; cin >> DestLon;
                            cout << "Calculating distance";
                            for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            DestLatArc = ((2*pi)/360)*DestLat;
                            DestLonArc = ((2*pi)/360)*DestLon;
                            distanceDepDest=6378.388 * acos(sin(DepLatArc) * sin(DestLatArc) + cos(DepLatArc) * cos(DestLatArc) * cos(DestLonArc - DepLonArc));
                            cout << "The distance between " << DepAirport << " and your alternate Airport is " << DestAirport << " is " << distanceDepDest << " km!\n";
                            cout << "Converting to nautical miles";
                            for(int i=1; i<= 2; ++i)
                            {
                                cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            distanceDepDestNM = distanceDepDest*0.539957;
                            cout << "Distance in nautical miles: " << distanceDepDestNM << " nm\n";
                            cout << "Calculating fuel amount for Boeing 747-400";
                            for(int i=1; i<= 5; ++i)
                            {
                                cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            tripfuel = fuelconsumptionB744*distanceDepDestNM+addamountStd;
                            cout << "Trip fuel: " << tripfuel << " lbs\n";
                            cout << "Multiplying with standard parameter";
                            for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            cruisefuelgtog = (tripfuel*fuelparameterStd);
                            cout << "The needed fuel amount for your cruise from Gate " << gate << " to the gate of your alt. airport (will be instructed by "
                            << " ATC) is " << cruisefuelgtog << " lbs\n";
                        }
                        if(aircraft == "LJ45" && cruisefuelgtog > maxfuellj45)
                        {
                           cout << "Error! Maximum fuel for Learjet 45 is " << maxfuellj45 << "! Please enter the amount you wanna subtract!\n" <<
                            "Please beware that you might be forced to use an alternate airport!" << endl << "Correction amount: ";
                            cin >> fuelcorrection;
                            " Calculating";
                            for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            correctedfuel = cruisefuelgtog - fuelcorrection;
                            cout << "Corrected fuel amount: " << correctedfuel << "Press 'Enter to continue!"; cin.get();
                            cout << "Loading map for alternate airports";
                            for(int i=1; i<=2;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            ShellExecute(NULL, "open", "https://maps.google.com", NULL, NULL, SW_SHOW);
                            cin.ignore();
                            cout << "Please tell me the ICAO of your alternate airport: "; getline(cin, altairport);
                            cout << "Latitude: "; cin >> DestLat;
                            cout << "Longitude: "; cin >> DestLon;
                            cout << "Calculating distance";
                            for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            DestLatArc = ((2*pi)/360)*DestLat;
                            DestLonArc = ((2*pi)/360)*DestLon;
                            distanceDepDest=6378.388 * acos(sin(DepLatArc) * sin(DestLatArc) + cos(DepLatArc) * cos(DestLatArc) * cos(DestLonArc - DepLonArc));
                            cout << "The distance between " << DepAirport << " and your alternate Airport is " << DestAirport << " is " << distanceDepDest << " km!\n";
                            cout << "Converting to nautical miles";
                            for(int i=1; i<= 2; ++i)
                            {
                                cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            distanceDepDestNM = distanceDepDest*0.539957;
                            cout << "Distance in nautical miles: " << distanceDepDestNM << " nm\n";
                            cout << "Calculating fuel amount for Learjet 45";
                            for(int i=1; i<= 5; ++i)
                            {
                                cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            tripfuel = fuelconsumptionLJ45*distanceDepDestNM+addamountLJ45;
                            cout << "Trip fuel: " << tripfuel << " lbs\n";
                            cout << "Multiplying with standard parameter";
                            for(int i=1; i<=5;++i)
                            {
                            cout << "."; Sleep(1000);
                            }
                            cout << ".\n\n";
                            cruisefuelgtog = (tripfuel*fuelparameterStd);
                            cout << "The needed fuel amount for your cruise from Gate " << gate << " to the gate of your alt. airport (will be instructed by "
                            << " ATC) is " << cruisefuelgtog << " lbs\n";
                        }
                        cout << "Saving data, please wait";
                        for(int i=1; i<=5;++i)
                        {
                            cout << "."; Sleep(1000);
                        }
                        cout << ".\n\n";
                        outfile.open("Flightplan.txt", ios::out | ios::app);
                        outfile << "Calculated fuel amount for trip Gate 2 Gate: " << cruisefuelgtog << endl;
                        outfile << "Alternate Airport: " << altairport << endl;
                        outfile << "Distance " << DepAirport << " to " << altairport << ":" << distanceDepDestNM << endl;
                        outfile.close();
                        cout << "Data successfully saved!\n";
                        cin.ignore();
                        cout << "To continue please type in 'yes', otherwise the aircraft's ICAO to calculate again!"; getline(cin, aircraft);
                    } while(aircraft != confirmexit);
                    // TOW and TOS Variables
                    double pasandluggageStdWeight = 220.0; // lbs
                    cout << pasandluggageStdWeight;
                    double passengers; // user input
                    double emptyweightb738 =  90170.0; // lbs
                    cout << emptyweightb738;
                    double emptyweightb744 = 404845.0; // lbs
                    cout << emptyweightb744;
                    double emptyweightlj45 =  13550.0; // lbs
                    cout << emptyweightlj45;
    
                    double reftakeoffweightb738 = 140507.0; // lbs
                    double reftakeoffspeedb738 = 163.0; // knots
                    double reftakeoffweightb744 = 846365.0; // lbs
                    double reftakeoffspeedb744 = 205.0; // knots
                    double reftakeoffweightlj45 = 20500.0; // lbs
                    double reftakeoffspeedlj45 = 175.0; // knots
    
                    double maxtakeoffweightb738 = 172500.0; // lbs
                    double maxtakeoffweightb744 = 910000.0; // lbs
                    double maxtakeoffweightlj45 =  20500.0; // lbs
    
                    double takeoffweight;
                    double takeoffspeed;
                    // TOW and TOS Calculation
    
                    cout << "Please enter the no. of passengers for this trip (no+.0): "; cin >> passengers;
                    cout << passengers;
                    double toweightbasic = passengers*pasandluggageStdWeight; cout << toweightbasic;
                    cout << "Calculating take off weight and speed";
                    for(int i=1; i<=5;++i)
                    {
                        cout << "."; Sleep(1000);
                    }
                    cout << ".\n\n";
                    if(aircraft == "B738")
                    {
                        takeoffweight = emptyweightb738+toweightbasic+cruisefuelgtog;
                        takeoffspeed = (takeoffweight/reftakeoffweightb738)*reftakeoffspeedb738;
                    }
                    if(aircraft == "B744")
                    {
                        takeoffweight = emptyweightb744+toweightbasic+cruisefuelgtog;
                        takeoffspeed = (takeoffweight/reftakeoffweightb744)*reftakeoffspeedb744;
                    }
                    if(aircraft == "LJ45")
                    {
                        takeoffweight = emptyweightlj45+toweightbasic+cruisefuelgtog;
                        takeoffspeed = (takeoffweight/reftakeoffweightlj45)*reftakeoffweightlj45;
                    }
                    cout << "Takeoff weight: " << takeoffweight << " lbs\n" << "Takeoff speed: " << takeoffspeed << " knots. Press 'Enter'!"; cin.get();
                    if(aircraft == "B738")
                    {
                        cout << "Maximum Takeoff Weight: " << maxtakeoffweightb738 << endl; Sleep(1000);
                    }
                    if(aircraft == "B744")
                    {
                        cout << "Maximum Takeoff Weight: " << maxtakeoffweightb744 << endl; Sleep(1000);
                    }
                    if(aircraft == "LJ45")
                    {
                        cout << "Maximum Takeoff Weight: " << maxtakeoffweightlj45 << endl; Sleep(1000);
                    }
                    // Save values and write further checklist
                    cout << "Saving values and writing further information to your flight plan. Please Wait";
                    for(int i=1; i<=2;++i)
                    {
                        cout << "."; Sleep(500);
                    }
                    cout << ".\n\n";
                    outfile.open("Flightplan.txt", ios::out | ios::app);
                    outfile << "Takeoff Weight: " << takeoffweight << endl;
                    outfile << "Takeoff Speed: " << takeoffweight << endl << endl;
                    cout << "Writing checklist of basic checks\n"; Sleep(1000);
                    outfile << "Please check https://vatmap.jsound.org/ for available ATC along your route" << endl;
                    outfile << "Squawk in Standby mode" << endl;
                    cout << "Writing checklist for inside checks\n"; Sleep(3000);
                    outfile << "Inside checks:" << endl << endl;
                    outfile << "All Instruments ok" << endl;
                    outfile << "Buttons are changing displays (don't forget altimeter)" << endl;
                    outfile << "Pitch and rudder trim possible" << endl;
                    outfile << "Thrust lever can be moved and is in idle position" << endl;
                    outfile << "Controller can be moved freely" << endl << endl;
                    cout << "Writing checklist for outside checks\n"; Sleep(5500);
                    outfile << "Outside checks" << endl << endl;
                    outfile << "Rudder straight and in good condition" << endl;
                    outfile << "Pitch elevator moves to its full extent" << endl;
                    outfile << "Aileron moves to its full extent left and right" << endl;
                    outfile << "Spoilers work properly" << endl;
                    outfile << "Fuselage is clean and there are no indications of damage" << endl;
                    outfile << "Pitot static receivers are free" << endl;
                    outfile << "Flaps work" << endl;
                    outfile << "Wings' surface is in good condition" << endl;
                    outfile << "Gear (main and front) look fine as well as their undercarriage bays" << endl;
                    outfile << "Engines (back and front) clear of dirt and any other things that don't belong there" << endl << endl;
                    cout << "Writing checklist for ATC Checks\n"; Sleep(1500);
                    outfile << "ATC Checks:" << endl << endl;
                    outfile << "Turn in to ATIS and note everything needed here:" << endl << endl << endl << endl << endl << endl << endl;
                    outfile << "Contact clearance delivery / ground for clearance for route (to speak press 'Ä') and note everything here: "
                    << endl << endl << endl << endl << endl << endl << endl << endl;
                    cout << "Writing checklist for Ground Service\n"; Sleep(3500);
                    outfile << "Ground services" << endl << endl;
                    outfile << "Request ground service:" << endl << endl;
                    outfile << "Fuel truck - requested / complete" << endl << endl;
                    outfile << "Catering service - requested / complete" << endl << endl;
                    outfile << "Boarding - requested / complete" << endl << endl;
                    outfile << "Push back clearance by ATC received - East / West / North / South" << endl << endl;
                    outfile << "Push back (and deicing) - requested / complete" << endl << endl;
                    cout << "Writing 'Before Taxi' checklist\n"; Sleep(3000);
                    outfile << "Before taxi checks:" << endl << endl;
                    outfile << "Startup clearance by ATC received" << endl;
                    outfile << "Engines idle and synchronised" << endl;
                    outfile << "Flaps to 5 (up to " << maxtakeoffweightb738 << " lbs)" << endl;
                    outfile << "Taxi clearance by ATC received" << endl;
                    outfile << "'Follow me' or chart" << endl << endl;
                    cout << "Writing 'Before Takeoff Checklist'\n"; Sleep(2500);
                    outfile << "Before Takeoff checklist" << endl << endl;
                    outfile << "All announcements made" << endl;
                    outfile << "Seatbelts, No Smoking (and deicing) switches in on - position" << endl;
                    outfile << "Departure route briefing (read from this list)" << endl;
                    outfile << "Explicit takeoff clearance by ATC received" << endl << endl;
                    cout << "Writing 'After Takeoff' checklist\n"; Sleep(2500);
                    outfile << "After Takeoff checklist" << endl << endl;
                    outfile << "Positive and stable climbing rate" << endl;
                    outfile << "Thrust to climb" << endl;
                    outfile << "Gear up" << endl;
                    outfile << "Flaps as you wish" << endl << endl;
                    cout << "Writing 'During flight' checklist\n"; Sleep(1000);
                    outfile << "During flight checklist" << endl << endl;
                    outfile << "Fuel checks every 30 minutes" << endl << endl;
                    cout << "Writing 'Fuel' checklist\n"; Sleep(3000);
                    outfile << "Fuel checklist" << endl << endl;
                    outfile << "Rest of distance to " << DestAirport << " or " << altairport << " (see FPL on GPS):" << endl;
                    outfile << "Fuel consumption per mile B738: " << fuelconsumptionB738 << endl << "B744: " << fuelconsumptionB744
                    << endl << "LJ45: " << fuelconsumptionLJ45 << endl;
                    outfile << "Calculated fuel (fuel consumption * rest of distance):" << endl;
                    outfile << "Fuel on board:" << endl << endl;
                    cout << "Writing 'Procedures in case of emergency' checklist\n"; Sleep(4500);
                    outfile << "In case of emergency:" << endl << endl;
                    outfile << "Keep calm, take over manual control, tell ATC what's your problem and request meaningful things" << endl
                    << "In case of a (nearing) stall: Switch ALL automatic controls off and press the nose gently down and balance it"
                    << " while gently controlling the thrust" << endl;
                    outfile << "In every emergency: Tell ATC how much passengers you have on board and if you need an alternate airport for "
                    << "an emergency landing or pit stop" << endl;
                    outfile << "Problem announcements: " << endl << endl;
                    outfile << "Problem that may be fixable at first sight: 'Pan, Pan, Pan'" << endl;
                    outfile << "Real emergency: Mayday, Mayday, Mayday and further info as noted above" << endl << endl;
                    cout << "Writing list for information of " << DestAirport << endl; Sleep(3000);
                    outfile << DestAirport << " or " << altairport << " airport information:" << endl << endl;
                    outfile << "Runway, Lenght, Surface, Approach type (ILS, Visual), Frequency (if ILS), Course: " << endl << endl;
                    outfile << "Runway, Lenght, Surface, Approach type (ILS, Visual), Frequency (if ILS), Course: " << endl << endl;
                    outfile << "Runway, Lenght, Surface, Approach type (ILS, Visual), Frequency (if ILS), Course: " << endl << endl;
                    outfile << "Runway, Lenght, Surface, Approach type (ILS, Visual), Frequency (if ILS), Course: " << endl << endl;
                    outfile << "Runway, Lenght, Surface, Approach type (ILS, Visual), Frequency (if ILS), Course: " << endl << endl;
                    outfile << "Runway, Lenght, Surface, Approach type (ILS, Visual), Frequency (if ILS), Course: " << endl << endl;
                    outfile.close();
    
                } break;
                case('A'):
                    {
                        cout << "Welcome to the ATC training module\n";
    
                    } break;
                case('E'):
                    {
                        cout << "You are ready for the flight, press any key to start main apps"; cin.get();
                        cout << "Disconnecting! Goodbye!"; Sleep(2000);
    ShellExecute(NULL, "open", "C:\\Program Files (x86)\\Microsoft Games\\Microsoft Flight Simulator X\\fsx.exe",NULL,NULL,SW_SHOW);
                        Sleep(214000);
                        PlaySound(NULL, 0, 0);
    ShellExecute(NULL, "open", "C:\\Users\\Martin\\AppData\\Local\\vPilot\\vPilot.exe",NULL,NULL,SW_SHOW);
    
                    } break;
                default:
                {
                    cout << "Wrong selection!\n";
                } break;
            }
        } while(mchoice != 'E');
    
        return 0;
    }
    


  • Ich habs grad nochmals geprüft:

    Die relevanten Programmteile sind 1:1 dieselben.

    Im Testteil funkts klaglos und im Hauptprogramm nicht? Drum hab ich jetzt auch mal den gesamten Quellcode reinkopiert, denn irgendwas muss da ja anders sein, denn wie gibt es das sonst. Es ist ja auch ein und derselbe Compiler und dieselbe IDE mit genau denselben Grundeinstellungen!
    Wie gesagt ich wäre für Aufklärung sehr dankbar.
    Mit lieben Grüßen,

    Martin



  • Falls jemand für die Ausführung des Hauptcodes zusätzliche Daten benötigt, bitte ein kurzes Mail an m.pardatscher2017@gmail.com

    Danke!

    Lg Martin



  • Davon abgesehen daß mit ziemlicher Sicherheit kein Schwein 1124 Zeilen Code lesen wird, weißt was fehlt? Eingabe, Ausgabe und erwartete Ausgabe.



  • Du solltest zunächst mal dein Programm in einzelne Module aufteilen. Ist doch kein Wunder, dass du bei dem großen Klumpen an Quellcode nicht mehr durch siehst. Zum Beispiel könntest du ein Eingabemodul bauen, welches getrennt von dem Berechnungsmodul funktioniert. Auf die Art könntest du mit konstanten Werten z.B. das Berechnungsmodul testen ohne dass du bei jedem Test ständig 10.000 Zahlen und Codes eingeben musst. In dem Fall würdest du deinem Fehler auch effizienter auf die Spur kommen.

    So in dem Zustand wie das Programm gerade ist, bist du der einzige der da sinnvoll auf Fehlersuche gehen kann.



    1. Funktionen! Dein "main" hat mehr als 1300 Zeilen (nach clang-format Umformatierung). Versuche, KLEINE Funktionen zu schreiben.
    2. Wie viele Stellen musst du ändern, wenn du ein neues Flugzeug unterstützen willst? Extrem vielen! Mach dir doch ein struct und sammle darin die Daten:
    struct Plane {
      std::string name;
      double fuel_consumption;
      double max_fuel;
      double empty_weight;
      ... // weitere flugzeugspezifische Werte
    };
    

    Dann wählst du nur einmal das passende Flugzeugobjekt aus und musst nicht in jedem einzelnen Befehl eine if-Kaskade einbauen.

    Und zuletzt: schalte in deinem Compiler Warnungen ein!!
    Du solltest sowas bekommen wie:

    forum.cpp:407:47: warning: '&&' within '||' [-Wlogical-op-parentheses]
                if (topoints == 0 || topoints > 0 && topoints <= 3) // 5er
                                  ~~ ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
    forum.cpp:407:47: note: place parentheses around the '&&' expression to silence this warning
                if (topoints == 0 || topoints > 0 && topoints <= 3) // 5er
                                                  ^
                                     (                            )
    forum.cpp:709:32: warning: format specifies type 'char *' but the argument has type 'char (*)[i]' [-Wformat]
                scanf("%254[^\n]", &path);
                       ~~~~~~~     ^~~~~
    forum.cpp:716:42: warning: array subscript is of type 'char' [-Wchar-subscripts]
                    cout << " Path: " << path[i]
                                             ^~
    forum.cpp:921:21: warning: expression result unused [-Wunused-value]
                        " Calculating";
                        ^~~~~~~~~~~~~~
    forum.cpp:994:21: warning: expression result unused [-Wunused-value]
                        " Calculating";
                        ^~~~~~~~~~~~~~
    forum.cpp:1067:21: warning: expression result unused [-Wunused-value]
                        " Calculating";
                        ^~~~~~~~~~~~~~
    forum.cpp:1167:20: warning: unused variable 'reftakeoffspeedlj45' [-Wunused-variable]
                double reftakeoffspeedlj45 = 175.0;     // knots
                       ^
    forum.cpp:703:19: warning: unused variable 'out' [-Wunused-variable]
                FILE *out;
                      ^
    forum.cpp:704:22: warning: implicit conversion from 'int' to 'char' changes value from 255 to -1 [-Wconstant-conversion]
                char i = 255;
                     ~   ^~~
    forum.cpp:1189:67: warning: variable 'cruisefuelgtog' is uninitialized when used here [-Wuninitialized]
                    takeoffweight = emptyweightb738 + toweightbasic + cruisefuelgtog;
                                                                      ^~~~~~~~~~~~~~
    forum.cpp:854:34: note: initialize the variable 'cruisefuelgtog' to silence this warning
                double cruisefuelgtog;
                                     ^
                                      = 0.0
    

    (Die Zeilennummern werden bei dir nur ungefähr passen. Ich musste die Windows-spezifischen Dinge entfernen und habe das Programm zuvor it clang-format formatiert)

    Solange du so Dinge drin hast wie falsches scanf-Format und die Benutzung von uninitialisierten Variablen, musst du auf jeden Fall nachbessern. Aber wichtigste Bemerkung: teile dein Programm in Funktionen auf! Berechnung der Dinge sollte unbedingt separat von der Eingabe sein!



  • Hallo, vielen Dank für die vielen und schnellen Antworten ubd konstruktiven Tipps! Ich werde eure Ratschläge befolgen und mich wieder melden sollte es dann immer noch nicht funktionieren. Lg



  • @venezianer27 sagte in Problem beim Rechnen (manuell berechnetes Ergebnis != Programmausgabe):

    während das Programm ausgibt: 1.03069e+265

    Das kann passieren, wenn durch eine sehr kleine Zahl geteilt wird.

    Möglicherweise Problem mit einer Intergerdivision

    Das hast du wohl schon selber entdeckt

    da ließ es sich aber durch das richtige Definieren mit xx.00

    Wenn nur Integertypen an einer Rechnung beteiligt sind, dann rechnet C++ mindestens in int.
    Dabei wird der Ausdruck schrittweise zerlegt und jeder Teilausruck für sich betrachtet.
    Der Typ links vom = spielt dabei überhaupt keine Rolle.



  • du kannst einen Debugger benutzen oder auch mal Zwischenergebnisse ausdrucken.

    Welche andere Programmiersprache du auch vorher gelernt hast, schließe von deren Verhalten nicht auf das Verhalten von C++.
    Mach diech vorher schlau, ob das so ist.



  • Hallo auch dir Dirk danke für die Tipps!

    Ich bin jetzt gerade dabei mein Programm zu überarbeiten und stoße dabei auf ein anderes Problem. Ich habe u.a. Strukturen für die einzelnen Airports angelegt und schaffe es jetzt nicht die double elemente dieser Strukturen an die Berechnungsfunktion zu übergeben.

    Mein Ansatz war: distance=DistanceCalculator(DepAirport.Lon,...)

    Im Kopf der Funktion mit entsprechender deklaration. Die Strukturen sind global angelegt.

    Ich habs auch schon mit Zeigern probiert bzw anderen Operanden statt Punkt. Wie kann ich mit den gewünschten Elementen der struktur rechnen?

    struct sAirport
        {
            string nameofap;
            string ICAO;
            double Lat;
            double Lon;
        };
    
    sAirport DepAirport;
    sAirport DestAirport;
    
    // Distance Calculation
    double DistanceCalculator(double DepAirport.Lat, double DepAirport.Lon, double DestAirport.Lat, double DestAirport.Lon)
    {
        long double pi = 3.141592653589793238462643383279502884;
        long double DepLatArc = ((2*pi)/360)*DepAirport.Lat;
        long double DepLonArc = ((2*pi)/360)*DepAirport.Lon;
        long double DestLatArc = ((2*pi)/360)*DestAirport.Lat;
        long double DestLonArc = ((2*pi)/360)*DestAirport.Lon;
        double distanceDepDestKM = 6378.388 * acos(sin(DepLatArc) * sin(DestLatArc) + cos(DepLatArc) * cos(DestLatArc) * cos(DestLonArc - DepLonArc));
        cout << "The distance between " << DepAirport.nameofap << " and " << DestAirport.nameofap << " is " << distanceDepDestKM << " km!\n";
        cout << "Converting to nautical miles";
        for(int i=1; i<= 2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        double distanceDepDestNM = distanceDepDestKM*0.539957;
        cout << "Distance in nautical miles: " << distanceDepDestNM << " nm\n";
        return distanceDepDestNM;
    }
    ...
    cout << "Calculating distance";
        for(int i=1; i<=5; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        double distanceDepDestNM=DistanceCalculator(DepAirport.Lon,DepAirport.Lat, DestAirport.Lat, DestAirport.Lon);
    


  • schaffe es jetzt nicht

    Das heißt?



  • @manni66 sagte in Problem beim Rechnen (manuell berechnetes Ergebnis != Programmausgabe):

    schaffe es jetzt nicht

    Das heißt?

    daß er es nicht schafft. duh.

    @venezianer27 Aber die Frage ist eigentlich berechtigt. https://www.youtube.com/watch?v=tD4q3leE5Uw



  • @Swordfish Ja ich weiß ist missverständlich formuliert. Ne mein Problem ist ganz einfach, dass mir die Ideen ausgehen, bzw ich vl auch einfach zu wenig Erfahrung habe, wie ich mit Elementen einer Struktur außer Ein- und Ausgabe weiter arbeiten kann. Ich suche und finde immer nur dieselben Ansätze, die bei mir nicht hinhauen wollen. Bräuchte irgendein Wort, das meinen Knoten löst 😉 Ich möchte die Entfernung anhand der Breiten- und Längengrade berechnen. Nur egal wie ich sie der Funktion übergebe, er nimmt sie so nicht an.

    Das sind die Meldungen meines Compilers. Ich muss zugeben, ich habe erst vor zwei Wochen wieder mit dem Lernen begonnnen. Davor doch einige Zeit nicht.

    C:\Users\Martin\Desktop\ProgrammingNewf210319\Ave\Modules\Planning.cpp|28|error: expected ',' or '...' before '.' token|
    C:\Users\Martin\Desktop\ProgrammingNewf210319\Ave\Modules\Planning.cpp||In function 'void planning()':|
    C:\Users\Martin\Desktop\ProgrammingNewf210319\Ave\Modules\Planning.cpp|172|error: too many arguments to function 'double DistanceCalculator(double)'|
    C:\Users\Martin\Desktop\ProgrammingNewf210319\Ave\Modules\Planning.cpp|28|note: declared here|
    C:\Users\Martin\Desktop\ProgrammingNewf210319\Ave\Modules\Planning.cpp|183|error: expected constructor, destructor, or type conversion before '(' token|
    C:\Users\Martin\Desktop\ProgrammingNewf210319\Ave\Modules\Planning.cpp|184|error: expected unqualified-id before '{' token|
    ||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

    Aktueller Quellcode:

    #include <iostream>
    #include <ctime>
    #include <windows.h>
    #include <MMSystem.h>
    #include <cstring>
    #include <fstream>
    #include <cmath>
    
    using namespace std;
    
    ifstream infile;
    ofstream outfile;
    string pilotname;
    string saving;
    
    struct sAirport
        {
            string nameofap;
            string ICAO;
            double Lat;
            double Lon;
        };
    sAirport DepAirport;
    sAirport DestAirport;
    
    // Distance Calculation prototype
    
    double DistanceCalculator(double DepAirport.Lat, double DepAirport.Lon, double DestAirport.Lat, double DestAirport.Lon);
    
    extern void planning()
    {
        // Music
        PlaySound(TEXT("Music//Planungstool.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
        // Pilot name (is declared and used in main.cpp und müsste an die Funktion bei Aufruf übergeben werden, wodurch es aber keine void Funktion mehr wäre?
        string pilotname2;
        cout << "Please tell me your name again: "; getline(cin, pilotname2);
        // Definition Departure, Destination
        cout << "To start, please provide the name of your departure airport: "; getline(cin, DepAirport.nameofap);
        cout << "Loading list where to find ICAO Codes! Please search and take a note of the airport you need! Thanks!\n";
        cout << "To search for the name use CTRL+F and type the name!\n";
        for(int i=1; i<=2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        ShellExecute(NULL, "open", "FilesForReading\\ICAO.txt", NULL, NULL, SW_SHOW);
        cout << "ICAO of Departure airport: "; getline(cin, DepAirport.ICAO);
        cout << "Saving";
        for(int i=1; i<=2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
    
        outfile.open("FilesForOutputs\\Flightplan.txt", ios::out | ios::app);
        outfile << "Flight Plan for: " << pilotname2 << endl << endl;
        outfile << "Departure Airport (Name): " << DepAirport.nameofap << endl
                << "Departure Airport (ICAO): " << DepAirport.ICAO << endl;
        outfile.close();
        cout << "Data saved successfully!\n";
        // GATE
        string gate;
        cout << "Please define the gate manually! Your selection: "; getline(cin, gate);
        cout << "Saving...\n"; Sleep(500);
        outfile.open("FilesForOutputs\\Flightplan.txt", ios::out | ios::app);
        outfile << "Gate: " << gate << endl;
        outfile.close();
        // Local Time
        int loctime;
        cout << "Retrieving local time";
        for(int i=1; i<=2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        cout << "Please tell me the local time of your departure airport from the website being opened!\n";
        Sleep(1500);
        ShellExecute(NULL, "open", "https://www.timeanddate.com/worldclock///", NULL, NULL, SW_SHOW);
        cout << "Local time: "; cin >> loctime; cin.ignore();
        cout << "Saving data";
        for(int i=1; i<=2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        outfile.open("FilesForOutputs\\Flightplan.txt", ios::out | ios::app);
        outfile << "Local Time: " << loctime << endl;
        outfile.close();
        cout << "Data saved successfully!\n"; Sleep(1000);
        // Destination airport
        cout << "Where do you wanna go?\n" << "Name of Destination: ";
        Sleep(1500);
        getline(cin, DestAirport.nameofap);
        cout << "Loading list where to find ICAO Codes! Please search and take a note of the airport you need! Thanks!\n";
        cout << "To search for the name use CTRL+F and type the name!\n";
        for(int i=1; i<=2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        ShellExecute(NULL, "open", "FilesForReading\\ICAO.txt", NULL, NULL, SW_SHOW);
        cout << "Please tell me the ICAO: "; getline(cin, DestAirport.ICAO);
        cout << "Saving";
        for(int i=1; i<= 2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        outfile.open("FilesForOutputs\\Flightplan.txt", ios::out | ios::app);
        outfile << "Destination airport (Name): " << DestAirport.nameofap << endl
                << "Destination airport (ICAO): " << DestAirport.ICAO << endl;
        outfile.close();
        cout << "Data saved successfully!\n";
        // Aircraft
        string aircraft;
        cout << "Please choose your aircraft for this flight from the list being opened!\n";
        for(int i=1; i<= 2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        cout << "Aircraft (ICAO): "; Sleep(2000);
        ShellExecute(NULL, "open", "FilesForReading\\Aircrafts.txt", NULL, NULL, SW_SHOW);
        getline(cin, aircraft);
        cout << "Saving";
        for(int i=1; i<= 2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        outfile.open("FilesForOutputs\\Flightplan.txt", ios::out | ios::app);
        outfile << "Aircraft: " << aircraft << endl;
        outfile.close();
        cout << "Data saved successfully!\n";
        // Airline and Flightnumber
        string airline;
        string flightnumber;
        string airlineICAO;
        cout << "Airline: "; getline(cin, airline);
        cout << "Flightnumber (google flights): "; getline(cin, flightnumber);
        cout << "ICAO Code of Airline (Link will be opened): "; Sleep(1500);
        ShellExecute(NULL, "open", "http://www.flugzeuginfo.net/table_airlinecodes_airline_dt.php", NULL, NULL, SW_SHOW);
        getline(cin, airlineICAO);
        cout << "Saving";
        for(int i=1; i<= 2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        outfile.open("Flightplan.txt", ios::out | ios::app);
        outfile << "Airline: " << airline << " " << flightnumber << "(" << airlineICAO << ")" << endl;
        outfile.close();
        cout << "Data saved successfully!\n";
        // Distance
        // Collecting necessary data
        cout << "Please provide the geographical data of your departure airport (Link will be opened)!\n"
             << "(Decimal degrees Latitude): "; Sleep(1500);
        ShellExecute(NULL, "open", "https://developers.google.com/maps/documentation/geocoding/intro#GeocodingRequests", NULL, NULL, SW_SHOW);
        cin >> DepAirport.Lat;
        cout << "Longitude: "; cin >> DepAirport.Lon;
        cout << "Now the same for your destination! Latitude: "; Sleep(1500);
        ShellExecute(NULL, "open", "https://developers.google.com/maps/documentation/geocoding/intro#GeocodingRequests", NULL, NULL, SW_SHOW);
        cin >> DestAirport.Lat;
        cout << "Longitude: "; cin >> DepAirport.Lon;
        // Calculation of distance
        cout << "Calculating distance";
        for(int i=1; i<=5; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        double distanceDepDestNM=DistanceCalculator(DepAirport.Lat, DepAirport.Lon, DestAirport.Lat, DestAirport.Lon);
        cout << "The distance between " << DepAirport.nameofap << " and " << DestAirport.nameofap << " is " << distanceDepDestNM << " nm!\n";
        cout << "Saving";
        for(int i=1; i<= 2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        outfile.open("Flightplan.txt", ios::out | ios::app);
    }
    
    DistanceCalculator(DepAirport.Lat, DepAirport.Lon, DestAirport.Lat, DestAirport.Lon);
    {
        long double pi = 3.141592653589793238462643383279502884;
        long double DepLatArc = ((2*pi)/360)*DepAirport.Lat;
        long double DepLonArc = ((2*pi)/360)*DepAirport.Lon;
        long double DestLatArc = ((2*pi)/360)*DestAirport.Lat;
        long double DestLonArc = ((2*pi)/360)*DestAirport.Lon;
        double distanceDepDestKM = 6378.388 * acos(sin(DepLatArc) * sin(DestLatArc) + cos(DepLatArc) * cos(DestLatArc) * cos(DestLonArc - DepLonArc));
        cout << "The distance between " << DepAirport.nameofap << " and " << DestAirport.nameofap << " is " << distanceDepDestKM << " km!\n";
        cout << "Converting to nautical miles";
        for(int i=1; i<= 2; ++i)
        {
            cout << "."; Sleep(1000);
        }
        cout << ".\n\n";
        double distanceDepDestNM = distanceDepDestKM*0.539957;
        cout << "Distance in nautical miles: " << distanceDepDestNM << " nm\n";
        return distanceDepDestNM;
    }
    ```cpp
    
    


  • Sag mal, hast du den Ausdruck Spaghetticode schonmal gehört?

    double DistanceCalculator(double DepAirport.Lat, double DepAirport.Lon, double DestAirport.Lat, double DestAirport.Lon)
    
    

    Name Du geben deine Variable in main() nix haben zu tun mit name von deine Parameter von Funktion DistanceCalculator().

    Du wollen

    double DistanceCalculator(sAirport DepAirport, sAirport DestAirport)
    


  • @Swordfish sagte in Problem beim Rechnen (manuell berechnetes Ergebnis != Programmausgabe):

    Du wollen
    double DistanceCalculator(sAirport DepAirport, sAirport DestAirport)

    Das sehe ich anders. Eine Funktion, den Abstand zwischen zwei Punkten auf der Erde zu berechnen, ist unabhängig von Flughäfen. Diese Funktion sollte also auch keine sAirport als Parameter haben.

    Im Allgemeinen ist es hilfreich, Funktionen mit Kleinbuchstaben benennen, Klassen mit Großbuchstaben / Hauptwörtern. Häufig nimmt man Verben als Namen. Es handelt sich hier nicht um einen Entfernungsrechner (das wäre ein Name für eine Klasse), sondern um eine Funktion "berechne Entfernung". Hier kann man auch noch spezifischer sein und diese Funktion z.B. "berechne Erdoberflächenentfernung" nennen. Das Verb "berechne" ist relativ bedeutungsarm und kann weggelassen werden. Ich würde sie letztendlich
    double earthSurfaceDistance(double lon1, double lat1, double lon2, double lat2);
    nennen (du kannst Parameter nicht "a.b" nennen, in den Namen darf kein Punkt vorkommen!). Wichtig noch: Aus eigener Erfahrung mit exakt dieser Funktion kann ich empfehlen, hier Typsicherheit einzubauen und eine Klasse Longitude und eine Latitude zu erstellen, damit man lon und lat nicht versehentlich vertauschen kann. (Man kann auch noch 1 lon/lat-Paar zu einem EarthSurfacePoint zusammenfassen - aber dann besteht weiter das Problem, wie man diesen korrekt initialisiert.) Und der Rückgabewert - tja, entweder boost::units verwenden oder irgendwie anders klar machen, in welcher Einheit der Wert zurückkommt - als "Billiglösung für Übungen" kommt dabei in Frage, die Einheit in den Funktionsnamen zu schreiben, also z.B. double earthSurfaceDistance_km(...).

    So eine Funktion kann man auch ohne Kenntnis von Flughäfen testen (daher würde ich NICHT zwei Airports als Parameter nehmen (wofür das "s" in "sAirport"? - ich würde es weglassen). - Oder höchstens als convenience-Funktion, die dann die von Airports unabhängige Funktion aufruft.

    @venezianer27: du vermischt hier schon wieder die Berechnung mt Ein- und Ausgabe! Stell dir mal vor, du willst die Entfernung von FRA zu jedem anderen Flughafen weltweit berechnen. Willst du dann wirklich jedes mal eine Sekunde schlafen?



  • Ok super danke @wob . Ich habe es jetzt so gemacht, wie du vorgeschlagen hast und auch die unnötige Vermischung von Berechnung und Ein / Ausgabe weg gelassen. Eine frage hätte ich aber noch: Du hast ja gemeint, dass es gut wäre eine Klasse Latitude und eine für die Longitude Werte zu benutzen! Die Klassen sehen bei mir jetzt so aus:

    class Latitude
    {
    public:
        // Members
        double DepLat;
        double DestLat;
        // Memberfunktion
        void showdata() // Funktion die mit diesen Werten sobald definiert arbeiten kann.
        {
            cout << "Latitude of Departure Airport: " << DepLat << endl;
            cout << "Latitude of Destination Airport: " << DestLat << endl;
        }
    };
    class Longitude
    {
    public:
        // Members
        double DepLon;
        double DestLon;
        // Memberfunktion
        void showdata()
        {
            cout << "Longitude of Departure Airport: " << DepLon << endl;
            cout << "Longitude of Destination Airport: " << DestLon << endl;
        }
    
    };
    

    Die Ausgabefunktionen sind jetzt nur mal da für Testzwecke, ich lerne gerade mit Klassen umzugehen. Und wie kann ich die Werte die der User definiert und ja nun in der Klasse deklariert sind für meine Funktion nutzen? Denn innerhalb einer Klasse können und dürfen ja keine Initialisierungen stattfinden, hab ich gelesen. Deshalb wäre es eher unvorteilhaft die Funktion der Berechnung in die Klasse als Memberfunktion einzuspeisen, mal abgesehen davon, dass ich dann nur die halben Werte habe weil es ja zwei Klassen sein sollen.



  • PS. bzw. wie kann ich die für die Funktion nötigen Werte aus der Klasse rausholen? Ich glaube ich versteh da noch einiges miss. Bitte verzeiht



  • @venezianer27 sagte in Problem beim Rechnen (manuell berechnetes Ergebnis != Programmausgabe):

    class Latitude
    {
    public:
    // Members
    double DepLat;
    double DestLat;

    Wir haben offenbar aneinander vorbei geredet.

    ich meinte sowas in der Art

    struct Latitude {
      explicit Latitude(double lat) : lat(lat) {} //wichtig: hier mit explicit arbeiten!
      double lat;
    };
    

    Also im Prinzip nur EIN double, der einen anderen Namen hat, damit man die nicht vertauschen kann.

    Damit zwingst du dich zu schreiben
    distance = earthDistance(Longitude(9.837), Latitude(53.536), Longitude(9.988), Latitude(53.630));

    sieht zwar komplizierter aus als earthDistance(9.837, 53.536, 9.988, 53.630);
    aber macht verwechslungen unwahrscheinlicher. Ich kann mir nie merken, in welcher Reihenfolge man Länge und Breite nimmt. Im ersten Fall kompiliert der Kram nicht, wenn ich den falschen Typ habe.

    Mach dein Programm erst einmal ohne solche "Kleinigkeiten" fertig.

    Die andere Variante ist:

    struct GeoCoordinates {
      double lat, lon;
    };
    
    double earthSurfaceDistance(GeoCoordinates a, GeoCoordinates b);
    

    Das ist wahrscheinlich noch besser.



  • Hi @wob dankeschön jetzt hab ich schon ein etwas klareres Bild. Das heißt im Klartext muss ich dann 4 Strukturen im gesamten anlegen, oder? also:

    struct Latitude {
      explicit Latitude(double lat) : lat(lat) {} //wichtig: hier mit explicit arbeiten!
      double lat;
    };
    

    für den Start und den Ziepunkt?

    LG


Log in to reply