0

I'm creating a programme about drone.I got no error when building it but when it comes to debugging this error appears

enter image description here

Can anyone explain to me why this happens? and how to solve this? I'm sorry if my coding line is hard to understand and not organized because im still learning.And i do know that the coding line itself doesnt make sense (drone part) thank you so much

    #include<iostream>
    #include <fstream>
    #include <cstdlib>
    #include <iomanip>

    using namespace std;

    void manualMode();
    void defaultMode();


    int speed, timeTofly, operation;
    int angle = 90;

    int main() {
        int mode = 0, part = 3;
        double flyLevel;
        int obstacleSensor = 0, timer = 3, AccelerometerSensor = 0, tempSensor = 25;
        char startPause;
        cout << "Drone Flying Technology" << endl;
        do {
            cout << "Choose Mode: (1)Default, (2)Manual \n";
            cin >> mode;
            if (mode == 1)
                defaultMode();
            if (mode == 2)
                manualMode();
        } while (mode == 0);

        cout << "Choose how to fly: (1)Upper , (2)Lower , (3)Upper and Lower \n";
        cin >> part;
        switch (part) {
        case 1:
        case 2:
            flyLevel = 0.5;
            break;
        case 3:
            flyLevel = 1;
            break;
        }
        if (obstacleSensor == 0) {
            do {
                cout << "Press (S) to Start,and swing the propeller." << endl;
                cin >> startPause;
                cout << "LED is On\n";
                while (AccelerometerSensor != flyLevel) {
                    AccelerometerSensor++;
                }
                cout << "Flying session Started! Time Left:" << timeTofly << endl;
                cout << "Eagle eye Operation Started!\n";
                timeTofly = timeTofly / 2;
                cout << "Crusing mode initiate Time Left:" << timeTofly << endl;
                timeTofly = timeTofly / 2;
                cout << "Free fly commenced Time Left:" << timeTofly << endl;
                timeTofly = 0;
                startPause = 'P';
            } while ((startPause == 's') || (startPause == 'S'));
        }
        cout << "End!\nLED is Off";
        return 0;
    }


    void manualMode() {
        cout << "Enter drone speed (knot) \n";
        cin >> speed;
        cout << "Enter Time to fly: \n";
        cin >> timeTofly;
        cout << "Choose Operation: (1)Fully manual, (2)Normal Orientation, (3)Free orientation, (4)FPV racing, (5)All\n";
        cin >> operation;
    }
    void defaultMode() {
        int howtofly;
        cout << "how to fly: (1)Circle, (2)Altitude Hold, (3)Free orientation";
        cin >> howtofly;
        switch (howtofly) {
        case 1:
            speed = 30;
            timeTofly = 3;
            break;
        case 2:
            speed = 40;
            timeTofly = 3;
            break;
        case 3:
            speed = 60;
            timeTofly = 3;
            break;
        }


        char object[25];
        char imei[5];
        float m1;

        ofstream outputFile("object to record and preferred speed.txt", ios::out);
        cout << "Please enter object to record,your drone imei number and video frame per second:\n";
        cout << "\nPress <ctrl> + z to stop. \n";

        while (cin >> object >> imei >> m1)
        {
            outputFile << object << " " << imei << " " << m1 <<endl;
        }





    }
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • 2
    It means the array `imei` on the stack trace was corrupted (a.k.a overwritten) by some other variable. You should really learn [how to use a debugger](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems). – Ruks Jun 20 '20 at 07:46
  • You can reach more people who might help you if you provide a textual quote of the error message right here. – Yunnosch Jun 20 '20 at 07:46
  • 1
    Did you hit "Retry"? That is what that the assert message box is requesting you do to debug the application. – PaulMcKenzie Jun 20 '20 at 07:47
  • 1
    What input did you enter? `char object[25];` can take only 24 characters, `char imei[5];` only 4 (last one is for the terminating `'\0'`). Probably you have an overflow here, it's better to use `std::string`. – Lukas-T Jun 20 '20 at 07:49
  • Use `std::string`s as @churill said. Also, 4 chars for an [imei](https://en.wikipedia.org/wiki/IMEI) sounds really small. – Ted Lyngmo Jun 20 '20 at 08:24

0 Answers0