I want to build a programme about drone which user can enter either default mode or manual mode .. and in default mode i want the programme to further asking user to input Object,imei,and video frame rates ( fstream method ) and actual frame rate (by pass reference) .When I build it it only stated warning which is "Warning C6001 Using uninitialized memory 'flyLevel' line 54" and still succeed and then I debug it and suddenly those error appeared "check failure#2-Stack around variable 'object ' was corrupted"and"check failure#2-Stack around variable 'id' was corrupted".I have google it and i dont understand why this happens.Can anyone explain to why this happens and how to solve this? thank you so much
#include<iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <string.h>
using namespace std;
void manualMode();
void defaultMode();
void Getdata(double& camrecord, double& projectfps);
void calculate(double& camrecord, double& projectfps, double& actual);
void Displayactualframerate(double& out);
int speed, timeTofly, operation;
int angle = 90;
double camrecord ;
double projectfps ;
double actual, out ;
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 (flyLevel != AccelerometerSensor) {
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\n";
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[5];
char id[5];
float m1, m2, m3, m4, m5;
ofstream outputFile("droneinfo.txt", ios::out);
cout << "Please enter object you want to record,set your drone id number (5 number) and your 5 preferred video fps:\n";
cin >> id >> object >> m1 >> m2 >> m3 >> m4 >> m5;
outputFile << id << " " << object << " " << m1 << " " << m2 << " " << m3 << " " << m4 << " " << m5<<endl;
Getdata(camrecord, projectfps);
calculate(camrecord, projectfps, actual);
Displayactualframerate(actual);
}
void Getdata(double& camrecord, double& projectfps) {
cout << "Please enter cam recording =" << camrecord << "f/s ,\nDesired footage frame rate="
<< projectfps<<"f/s\n";
cin >> camrecord;
cin >> projectfps;
}
void calculate(double& camrecord, double& projectfps, double& actual) {
actual = (camrecord / projectfps);
}
void Displayactualframerate(double& out) {
cout << "\nThe actualframerate is =" << out << " f/s\n";
}
What I have tried:
I try to change all "flyLevel" to another string and it doesn't work