I have recently switched from dev c++ on windows to an osx dev environment and am trying to use sublime text 3. However, when I run my program, I get a segmentation fault. Here is the error message:
/bin/bash: line 1: 20506 Segmentation fault: 11 "/Users/jimi/Documents/University/lab0603"
[Finished in 1.2s with exit code 139]
[shell_cmd: g++ "/Users/jimi/Documents/University/lab0603.cpp" -o "/Users/jimi/Documents/University/lab0603" && "/Users/jimi/Documents/University/lab0603"]
[dir: /Users/jimi/Documents/University]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
Here is the full code:
#include <iostream>
#include <cmath>
using namespace std;
string flightDirections[16] = {"ENE", "NE", "NNE", "N", "NNW", "NW", "WNW", "W", "WSW", "SW", "SWS", "S", "SSE", "SE", "ESE", "E"};
double cruisingSpeed = 0;
double windSpeed = 0;
int windDirection = 0;
double flightDistance = 0;
string numberToDirection(int direction) {
return (direction) ? "The wind is blowing from the East." : " The wind is blowing from the West.";
//this way we only have one return statement :)
}
void getInput () {
cout << "Hello! \n"
<< "Thank you for choosing to use this really great program!! \n"
<< "This program will compute the necessary heading adjustment for your flight,"
<< " and provide the estimated flight time. \n";
cout << "Enter the aircraft cruising speed in still air (in km/h): ";
cin >> cruisingSpeed;
cout << " \n \t cruising speed = " << cruisingSpeed << "\n Enter the wind speed in km/h: ";
cin >> windSpeed;
cout << " \n \t wind speed = " << windSpeed << "\n Enter 1 if the wind is blowing from the West and -1 if wind is blowing from the East:";
cin >> windDirection;
cout << "\n\t" << numberToDirection(windDirection) << "\n Enter the distance between the originating and destination cities, in km:";
cin >> flightDistance;
cout << "\n\t flight distance = " << flightDistance << "\n Enter the compass direction of the destination city, relative to the originating cities, using the following values:";
for (int i = 0; i < sizeof(flightDirections); i++) {
cout << i + 1;
cout << flightDirections[i];
}
cin.ignore();
}
int main() {
getInput();
return 0;
}
What is going on?